Write a program to accept two numbers and display the quotient as a result. In addition, an error message should be displayed if the second number is zero or greater than the first number.
Sample Solution
C# Sharp Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int n1, n2, result;
Console.WriteLine("Enter a Number");
n1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter second Number");
n2 = Convert.ToInt32(Console.ReadLine());
if (n2 != 0)
{
if (n2 < n1)
{
result = n1 / n2;
Console.WriteLine("Result is {0}", result);
}
else
{
Console.WriteLine("A number cannot be divide by a
number greater than itself");
}
}
else
{
Console.WriteLine("A nubber cannot bedivide by
zero");
}
Console.ReadLine();
}
}
}
Sample Output
Sample Output
No comments:
Post a Comment