C program to simulate a simple calculator to perform arithmetic operations like addition, subtraction,multiplication and division only on integers

by Nideesh C on April 12, 2011 · 1 comment

in C Programming




/* C program to simulate a simple calculator to perform arithmetic operations like addition, subtraction,multiplication and division only on integers. Error message should be reported if any attempt is made to divide by zero */

#include <stdio.h>
#include <conio.h>

void main()
{
char oper;            /* oper is an operator to be selected */
float n1, n2, result;

clrscr();

printf (“Simulation of a Simple Calculator\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);

}
/*—————————–
Output
Simulation of Simple Calculator

Enter two numbers
3 5
Enter the operator [+,-,*,/]
+

3.00 +  5.00=  8.00

RUN2
Simulation of Simple Calculator

Enter two numbers
12.75
8.45
Enter the operator [+,-,*,/]
-

12.75 -  8.45=  4.30

RUN3
Simulation of Simple Calculator

Enter two numbers
12 12
Enter the operator [+,-,*,/]
*

12.00 * 12.00= 144.00

RUN4
Simulation of Simple Calculator

Enter two numbers
5
9
Enter the operator [+,-,*,/]
/

5.00 /  9.00=  0.56

——————————*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Sample program (multiplication using addition)
  2. Write a C program to find the simple interest , given principle,rate of interest and times
  3. Sample – exponentiation using multiplication
  4. C program to find the biggest of three numbers
  5. C program to find and output all the roots of a quadratic equation, for non-zero coefficients.

Leave a Comment

{ 1 trackback }

Previous post:

Next post: