Programming Course in C# ¡Free!

Multiply if not zero

 Friday, April 05, 2013 published by Exercises C#
Proposed exercise

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 product; otherwise, it will display "0".



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

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

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

if (x!=0 && y!=0) 
Console.WriteLine("{0} x {1} = {2}", 
x, y, x*y);
Console.WriteLine("{0} x {1} = {2}", 
x, y, 0);