Program:
#include<stdio.h>
int main()
{
char op;
float n1,n2,res;
printf("Enter two numbers: \n");
scanf("%f %f",&n1,&n2);
printf("Enter Operation (+,-,*,/): ");
fflush(stdin);
scanf("%c",&op);
switch(op)
{
case '+': res=n1+n2;
break;
case '-': res=n1-n2;
break;
case '*': res=n1*n2;
break;
case '/': res=n1/n2;
break;
default : printf("Invalid");
}
printf("Result: %.2f",res);
return 0;
}
Output:
#include<stdio.h>
int main()
{
char op;
float n1,n2,res;
printf("Enter two numbers: \n");
scanf("%f %f",&n1,&n2);
printf("Enter Operation (+,-,*,/): ");
fflush(stdin);
scanf("%c",&op);
switch(op)
{
case '+': res=n1+n2;
break;
case '-': res=n1-n2;
break;
case '*': res=n1*n2;
break;
case '/': res=n1/n2;
break;
default : printf("Invalid");
}
printf("Result: %.2f",res);
return 0;
}
Output:
No comments:
Post a Comment