Tuesday, August 10, 2010

SIMPLE CALCULATOR

0 comments
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
char opr;
int a,b;
float result=0;
clrscr();
printf("Enter the first number:");
scanf("%d",&a);
printf("Enter the second number:");
scanf("%d",&b);
printf("Enter the operator:");
scanf("%s",&opr);
switch(opr)
{
case'+':
result=a+b;
break;
case'-':
result=a-b;
break; 
case'*':
result=a*b;
break; 
case'/':
result=a/b;
break; 
case'%':
result=a%b;
break;
default:
printf("You are entered a invalid operator");
break;
}
printf("The result of %d %c %d is= %f",a,opr,b,result);
getch();
}





Leave a Reply