Q:

Write a C# Sharp program that takes two numbers as input and perform an operation (+,-,*,x,/) on them and displays the result of that operation

0

Write a C# Sharp program that takes two numbers as input and perform an operation (+,-,*,x,/) on them and displays the result of that operation

Sample Output:

Input first number: 4                                                                                         
Input operation: *                                                                                            
Input second number: 4                                                                                        
4 * 4 = 16

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public class Exercise4
{
    public static void Main()
    {
        int x, y;
        char operation;
         
        Console.Write("Input first number: ");
        x = Convert.ToInt32(Console.ReadLine());
        Console.Write("Input operation: ");
        operation = Convert.ToChar(Console.ReadLine());
        Console.Write("Input second number: ");
        y = Convert.ToInt32(Console.ReadLine());
         
        if (operation=='+')
            Console.WriteLine("{0} + {1} = {2}", x, y, x+y);
        else if (operation=='-')
            Console.WriteLine("{0} - {1} = {2}", x, y, x-y);
        else if ((operation=='x') || (operation=='*'))
            Console.WriteLine("{0} * {1} = {2}", x, y, x*y);
        else if (operation=='/')
            Console.WriteLine("{0} / {1} = {2}", x, y, x/y);
        else
            Console.WriteLine("Wrong Character");
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now