Description: Simple Calculator is a C language-based application used for performing all the simple arithmetic operations like addition, multiplication, division, and subtraction. The application can be made using basic knowledge of C like if-else statements, loops, etc. The functionalities of the application are mentioned below: Addition Subtraction Multiplication Division Logarithmic values Square roots
#include
int main()
{
char ch;
double a,b;
printf("Enter operator(+,-,*,/)","enter exit press x:");
scanf("%c",&ch);
if(ch=='x')
exit(0);
printf("Enter two operand:");
scanf("%lf %lf",&a,&b);
switch(ch){
//for addition
case'+':
printf("%lf+%lf=%lf",a,b,a+b);
break;
//for subtraction
case'-':
printf("%lf-%lf=%lf",a,b,a-b);
break;
//for multiplication
case'*':
printf("%lf*%lf=%lf",a,b,a*b);
break;
//for subtraction
case'/':
printf("%lf/%lf=%lf",a,b,a/b);
break;
default:
printf("wrong! unavilable press");
}
}
Output
Enter an operator (+, -, *, /), if want to exit press x: +
Enter two first and second operand: 7 8
7.0 + 8.0 = 15.0
Enter an operator (+, -, *, /), if want to exit press x: -
Enter two first and second operand: 8 9
8.0 - 9.0 = -1.0
Enter an operator (+, -, *, /), if want to exit press x: *
Enter two first and second operand: 8 7
8.0 * 7.0 = 56.0
Enter an operator (+, -, *, /), if want to exit press x: /
Enter two first and second operand: 8 3
8.0 / 3.0 = 2.7
Enter an operator (+, -, *, /), if want to exit press x: x
Comments
Post a Comment