21CSL582 Program 1

1. Develop a C# program to simulate simple arithmetic calculator for Addition, Subtraction, Multiplication, Division and Mod operations. Read the operator and operands through console.

using System;
public class Arthematic
{
    public static void Main(string [] args)
    {
        System.Console.WriteLine("Enter a First Number: ");
        int num1 = Convert.ToInt32(Console.ReadLine());
        System.Console.WriteLine("Enter a Second Number: ");
        int num2 = Convert.ToInt32(Console.ReadLine());
        System.Console.WriteLine("{0} + {1} = {2}", num1, num2, num1 + num2);
        System.Console.WriteLine("{0} - {1} = {2}", num1, num2, num1 - num2);
        System.Console.WriteLine("{0} x {1} = {2}", num1, num2, num1 * num2);
        System.Console.WriteLine("{0} / {1} = {2}", num1, num2, num1 / num2);
        System.Console.WriteLine("{0} mod {1} = {2}", num1, num2, num1 % num2);
    }
}
Enter a First Number:
123
Enter a Second Number:
32
123 + 32 = 155
123 - 32 = 91
123 x 32 = 3936
123 / 32 = 3
123 mod 32 = 27

Leave a Reply

Your email address will not be published. Required fields are marked *