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);
if(op=='+')
res=n1+n2;
else if (op=='-')
res=n1-n2;
else if (op=='*')
res=n1*n2;
else if (op=='/')
res=n1/n2;
else
{
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);
if(op=='+')
res=n1+n2;
else if (op=='-')
res=n1-n2;
else if (op=='*')
res=n1*n2;
else if (op=='/')
res=n1/n2;
else
{
printf("Invalid");
}
printf("Result: %.2f",res);
return 0;
}
Output:
No comments:
Post a Comment