In this example, you will learn to create C Program to Make a Simple Calculator to perform all Arithmetic Operations.
This program takes an arithmetic operator +, -, *, / and two operands from the user. Then, it performs the calculation on the two operands depending upon the operator entered by the user.
PROGRAM :
#include<stdio.h>
int main()
{
int a,b,c,opt;
printf("Enter two number to calculate\n");
scanf("%d%d",&a,&b);
printf("\nEnter 1 for Addition\nEnter 2 for Subtraction\nEnter 3 for Multiplication\nEnter 4 for Division\n\n");
scanf("%d",&opt);
if(opt==1)
{
c = a+b;
printf("\nSum of %d and %d is %d\n",a,b,c);
}
else if(opt==2)
{
c = a-b;
printf("\nDifference between %d and %d is %d\n",a,b,c);
}
else if(opt==3)
{
c = a*b;
printf("\nMultiplication of %d by %d is %d\n",a,b,c);
}
else if(opt==4)
{
c = a/b;
printf("\nDivision of %d by %d is %d\n",a,b,c);
}
else
{
printf("\nIn appropriate option\n");
}
}