1.7 – Multiple operations with same numbers

Question


Write a program to accept two numbers from user and perform Addition, Subtraction, Multiplication and Division(Remainder and Quotient) and display in format given below

for ex.  enter first number = 13

enter second number = 4

13 + 4 = 17

13 – 4 = 9

13 * 4 = 52

13 / 4 = 3

13 % 4 = 1


Solution


class SameNumbersMultipleOperations
    {
        static void Main(string[] args)
        {
            int a, b, c, d, e, f, g;                  //initialization
            Console.Write(“Enter first number : “);
            a = Convert.ToInt16(Console.ReadLine());
            Console.Write(“Enter second number : “);
            b = Convert.ToInt16(Console.ReadLine());
            c = a + b;                      //calculation for addition     
            d = a – b;                      //calculation for subtraction
            e = a * b;                      //calculation for multiplication
            f = a / b;                      //calculation for quotient
            g = a % b;                      //calculation for remainder
            Console.WriteLine(“{0} + {1} = {2}”, a, b, c);
            Console.WriteLine(“{0} – {1} = {2}”, a, b, d);
            Console.WriteLine(“{0} * {1} = {2}”, a, b, e);
            Console.WriteLine(“{0} / {1} = {2}”, a, b, f);
            Console.WriteLine(“{0} % {1} = {2}”, a, b, g);
        }
    }

 Previous                                                Home                                                   Next


Output

7