Advertisement
Sathvikks8

Calculator.c

Dec 22nd, 2020
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. //C Program to solve simple computational problems using arithmetic expressions and use of each operator leading to stimulation of a commercial calculator
  2. #include<stdio.h>
  3. int main()
  4. {
  5.     while (1){
  6.     float a,b;
  7.     char op;
  8.     printf("\n");
  9.     printf("\n");
  10.     printf("\n");
  11.     printf("Enter the operator (+ - * / %%): ");
  12.     scanf("%c",&op);
  13.     printf("\nEnter the 2 operands: ");
  14.     scanf("%f%f",&a,&b);
  15.     switch(op)
  16.     {
  17.         case '+':
  18.         {
  19.             printf("%f + %f = %f",a,b,a+b);
  20.             break;
  21.         }
  22.         case '-':
  23.         {
  24.             printf("%f - %f = %f",a,b,a-b);
  25.             break;
  26.         }
  27.         case '*':
  28.         {
  29.             printf("%f * %f = %f",a,b,a*b);
  30.             break;
  31.         }
  32.         case '/':
  33.         {
  34.             printf("%f / %f = %f",a,b,a/b);
  35.             break;
  36.         }
  37.         case '%':
  38.         {
  39.             printf("%f %% %f = %d",a,b,((int)a%(int)b));
  40.             break;
  41.         }
  42.         default:
  43.         {
  44.             printf("Enter valid operator");
  45.         }
  46.     }
  47. }
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement