April 18, 2020

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.

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.





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


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.

If you enter first number and second number same then  you get below Output.

                                                        Sample Output

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.






No comments:

Post a Comment