# Basic Calculator

Discussion in 'C' started by Anil2447, Aug 28, 2010.

1. ### Anil2447Guest

$image=http://www.cfanatic.com/cgi-bin/mimetex.cgi?This+is+a+small+Program+i+have+written+to+perform+the+Basic+Operations.+Here+is+my+code+for+it.+Please+suggest+to+improve+more.................&hash=9e52c6c2a214b44b19d77a3a3856958c$3
#include
#include
int main()
{
char operator;
int num1, num2;
//char operation[1]={'\0'};
printf("Enter two numbers and operator to perform calculations!...\n");
printf("Enter the operator: ");
scanf("%c",&operator);
printf("Enter num1: ");
scanf("%d",&num1);
printf("Enter num2: ");
scanf("%d",&num2);

if (operator=='+')
{
printf("Sum is %d\n",num1+num2);
}
else if (operator=='-')
{
printf("Difference is %d\n",num1-num2);
}
else if (operator=='*'){
printf("Product is %d\n",num1*num2);
}
else if(operator=='/'){
printf("Ratio is %d\n",num1/num2);
}
else
printf("Not given any Operation.");
}$image=http://www.cfanatic.com/cgi-bin/mimetex.cgi?OUTPUT..........&hash=2e61cadd19582fb1a6a46a11e039072f$

Enter two numbers and operator to perform calculations!...

Enter the operator: +
Enter num1: 12
Enter num2: 13
Sum is 25

$image=http://www.cfanatic.com/cgi-bin/mimetex.cgi?Suggest....................:pretty:&hash=2bd276af906a408249706914b81115ed$