C program for given two numbers to perform arithmetic operations using switch statement

Spread the love

//* C program for given two numbers to perform arithmetic operations using switch statement.*//

 

 

#include<stdio.h>
#include<conio.h>
void main()
{
int ch;
float a,b,res;
clrscr();
printf(“Enter two numbers:”);
scanf(“%f%f”,&a,&b);
printf(“nMenun1.Additionn2.Subtractionn3.Multiplicationn4.Division”);
printf(“nEnter your choice:”);
scanf(“%d”,&ch);

switch(ch)
{
case 1: res=a+b;
break;
case 2: res=a-b;
break;
case 3: res=a*b;
break;
case 4: res=a/b;
break;
default: printf(“Wrong choice!!nPress any key…”);
getch();
exit(0);
}

printf(“nResult=%f”,res);
getch();
}

 

Output

arithmetic operations


Leave a Reply

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