Multiply if not zero Learn programming C#

Lesson:

Flow Control


Exercise:

Multiply if not zero


Objetive:

Write a C# program to ask the user for a number; if it is not zero, then it will ask for a second number and display their sum; otherwise, it will display "0"


Code:

using System;
public class exercise16
{
    public static void Main()
    {
        int x, y;

        Console.Write("enter x:");
        x = System.Convert.ToInt32(System.Console.ReadLine());

        if (x != 0)
        {
            Console.Write("enter y:");
            y = System.Convert.ToInt32(System.Console.ReadLine());
            Console.WriteLine("the product of {0} and {1} is {2}",
            x, y, x * y);
        }

        if (x == 0)
            Console.Write("0");
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.