Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.25 KB | None | 0 0
  1. #include<stdio.h>
  2. int main()
  3. {void menu (void);
  4. int add (int a1, int a2);
  5. int sub (int b1, int b2);
  6. int power (int c1, int c2);
  7. int multiply (int d1,int d2);
  8. int result=0,number1=0,number2;
  9. char ch;
  10. while (ch!='q')
  11. {
  12.     menu ();
  13.     scanf("%c%d",&ch,&number2);
  14.     if (ch=='+')
  15.         number1=add (number1,number2);
  16.  
  17.  
  18.     else if (ch=='-')
  19.         number1=sub (number1,number2);
  20.  
  21.     else if (ch=='*')
  22.         number1 =multiply (number1,number2);
  23.  
  24.     else if (ch=='^')
  25.         number1=power (number1,number2);
  26.  
  27. }
  28. return 0;}
  29. void menu ()
  30. {
  31.     printf("+ add\n");
  32.     printf("- subtract\n");
  33.     printf("* multiply\n");
  34.     printf("^ power\n");
  35.     printf("q quit\n");
  36. }
  37. int add (int a1, int a2)
  38. {
  39.     int resa;
  40.     resa=a1+a2;
  41.     printf("Result so far is %d\n",resa);
  42.     return resa;
  43. }
  44. int sub (int b1, int b2)
  45. {
  46.     int resb;
  47.     resb = b1-b2;
  48.     printf("Result so far is %d\n",resb);
  49.     return resb;
  50. }
  51. int power (int c1, int c2)
  52.     {int resc=1,pow=0;
  53.     while (pow!=c2)
  54.         {resc=resc*c1;
  55.         pow++;
  56.             }
  57.     printf("Result so far is %d\n",resc);
  58.     return resc;
  59. }
  60. int multiply (int d1,int d2)
  61.     {int resd;
  62.     resd= d1*d2;
  63.     printf("Result so far is %d\n",resd);
  64.     return resd;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement