Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {void menu (void);
- int add (int a1, int a2);
- int sub (int b1, int b2);
- int power (int c1, int c2);
- int multiply (int d1,int d2);
- int result=0,number1=0,number2;
- char ch;
- while (ch!='q')
- {
- menu ();
- scanf("%c%d",&ch,&number2);
- if (ch=='+')
- number1=add (number1,number2);
- else if (ch=='-')
- number1=sub (number1,number2);
- else if (ch=='*')
- number1 =multiply (number1,number2);
- else if (ch=='^')
- number1=power (number1,number2);
- }
- return 0;}
- void menu ()
- {
- printf("+ add\n");
- printf("- subtract\n");
- printf("* multiply\n");
- printf("^ power\n");
- printf("q quit\n");
- }
- int add (int a1, int a2)
- {
- int resa;
- resa=a1+a2;
- printf("Result so far is %d\n",resa);
- return resa;
- }
- int sub (int b1, int b2)
- {
- int resb;
- resb = b1-b2;
- printf("Result so far is %d\n",resb);
- return resb;
- }
- int power (int c1, int c2)
- {int resc=1,pow=0;
- while (pow!=c2)
- {resc=resc*c1;
- pow++;
- }
- printf("Result so far is %d\n",resc);
- return resc;
- }
- int multiply (int d1,int d2)
- {int resd;
- resd= d1*d2;
- printf("Result so far is %d\n",resd);
- return resd;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement