// A C program to perform arithmetic operations using switch case.
#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("Enter 1 for Additionn 2 for Subtractionn 3 for Multiplicationn and 4 for Division");
printf("\nEnter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
res=a+b;
printf("addition %f",res);
break;
case 2:
res=a-b;
printf("subtraction %f",res);
break;
case 3:
res=a*b;
printf("multiplication %f ",res);
break;
case 4:
res=a/b;
printf("division %f",res);
break;
default:
printf("Wrong choice!!\nPress any key");
}
getch();
}
Output:
Nhận xét
Đăng nhận xét