Write a program to perform arithmetical calculation using switch statement.
Write a program to perform arithmetical calculation using switch statement.
#include<stdio.h>
#include<conio.h>
void main()
{
float
num1,num2,res;
int choice;
clrscr();
printf("\n\t*************************************************************");
printf("\n\t*****************
Malhotra Computer Centre ******************");
printf("\n\t*************************************************************");
printf("\n\n\t-------------------------
Menu ----------------------------");
printf("\n\t\tProgram
to perform Arithmetical Operation :");
printf("\n\n\tPress
1 for Addition :" );
printf("\n\tPress
2 for Subtraction : ");
printf("\n\tPress
3 for Multiplication :");
printf("\n\tPress
4 for Division : ");
printf("\n\t-------------------------------------------------------------");
printf("\n\tInput
your choice :\t");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
printf("\n\tInput
any number : ");
scanf("%f",&num1);
printf("\n\tInput
any number : ");
scanf("%f",&num2);
res=num1+num2;
printf("\n\tThe
Result is : %0.2f",res);
break;
}
case 2:
{
printf("\n\tInput
any number : ");
scanf("%f",&num1);
printf("\n\tInput
any number : ");
scanf("%f",&num2);
res=num1-num2;
printf("\n\tThe
Result is : %0.2f",res);
break;
}
case 3:
{
printf("\n\tInput
any number : ");
scanf("%f",&num1);
printf("\n\tInput
any number : ");
scanf("%f",&num2);
res=num1*num2;
printf("\n\tThe
Result is : %0.2f",res);
break;
}
case 4:
{
printf("\n\tInput
any number : ");
scanf("%f",&num1);
printf("\n\tInput
any number : ");
scanf("%f",&num2);
res=num1/num2;
printf("\n\tThe
Result is : %0.2f",res);
break;
}
default:
{
printf("\n\tInvalid
choice!!!");
printf("\n\tPlease
read the instruction carefully and input a Valid choice");
break;
}
}
getch();
}
Comments
Post a Comment