#include <stdio.h>
#include<conio.h>
void main()
{
float num1,num2,result;
char op;
clrscr();
printf("\n type your expression(num1,num2) \n");
scanf("%f%f",&num1,&num2);
printf("\n enter the operator[+,-,*,/] \n");
scanf("%s",&op);
switch(op)
{
case '+':
result=num1+num2;
break;
case '-':
result=num1-num2;
break;
case '*':
result=num1*num2;
break;
case '/':
if(num2==0)
{
printf("\n division by zero is error");
}
else
{
result=num1/num2;
}
break;
default:
printf("\n invalid operator");
}
printf("\n %2f%c%2f=%2f",num1,num2,op,result);
getch();
}
No comments:
Post a Comment