Write a C program to simulate a simple calculator to perform arithmetic operations like addition,subtraction,multiplication and division only on integers.
#include <stdio.h> #include <conio.h> #include <stdio.h> #include <conio.h> int main() { char oper; float n1, n2, result; printf ("Simple Calculator Simulation \n\n"); printf("Enter two numbers\n"); scanf ("%f %f",&n1,&n2); fflush (stdin); printf("Enter the operator [+,-,*,/]\n"); scanf ("%c",&oper); switch (oper) { case '+': result = n1 + n2; break; case '-': result = n1 - n2; break; case '*': result = n1 * n2; break; case '/': result = n1 / n2; break; default : printf ("Error in operation\n"); break; } printf ("\n %5.2f %c %5.2f = %5.2f\n", n1,oper, n2, result); return 0; }
0 Comment to "Simple Calculator [ + , - , * , / ]"
Post a Comment