Aim:

              To perform the simple calculator using c sharp.net application.

Algorithms:

Step1: Create a new folder in a “d” drive and open the new text document in the folder.

Step2: Type the program in the new notepad file and save the file “simcalc”

Step3: Use the switch case to determine various operations in the program.

Step4: The operators are mainly used to perform the operations, Addition,subtraction,              +multiplication and division.

Step5: Save the program with the extension of .cs

Step6: Open the visual studio comment prompt to compile and run the program.

Step7: Compile the program & given the program name .cs

Step8: Run the program by giving the program name and stop the program.

Program:


using System;

class simcalc

{

public static void Main(string[] args)

{

double a,b,rpt=1;

int choice;

while(rpt!=0)

{

Console.WriteLine("select the operations:");

Console.WriteLine("1.addition");

Console.WriteLine("2.subtraction");

Console.WriteLine("3.multiplication");

Console.WriteLine("4.division");

Console.WriteLine("5.exit");

Console.WriteLine("Enter your choice:");

choice=int.Parse(Console.ReadLine());

switch(choice)

{

case 1:

Console.WriteLine("Enter two number:");

a=double.Parse(Console.ReadLine());

b=double.Parse(Console.ReadLine());

Console.WriteLine("Result of addition:"+(a+b));

break;

case 2:

Console.WriteLine("Enter two number:");

a=double.Parse(Console.ReadLine());

b=double.Parse(Console.ReadLine());

Console.WriteLine("Result of subtraction:"+(a-b));

break;

case 3:

Console.WriteLine("Enter two number:");

a=double.Parse(Console.ReadLine());

b=double.Parse(Console.ReadLine());

Console.WriteLine("Result of multiplication:"+(a*b));

break;

case 4:

Console.WriteLine("Enter two number:");

a=double.Parse(Console.ReadLine());

b=double.Parse(Console.ReadLine());

if(b==0)

{

Console.WriteLine("division not possible");

}

else

{

Console.WriteLine("resultof division:"+(a/b));

}

break;

case 5:

rpt=0;

break;

default:

Console.WriteLine("invalid selection");

break;

}

}

}

}



OUTPUT:




BY
      REGU RAM SV.

1 تعليقات

إرسال تعليق

أحدث أقدم