Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int power(int a, int b) {
- if (b == 1) return a;
- else { return (a*power(a, b - 1)); }
- }
- main() {
- int a;
- int b;
- char c = '+';
- while (c != '0') {
- scanf("%d%c%d", &a, &c, &b);
- if (c == '0') { break; }
- else if (c == '+' || c == '-' || c == '*' || c == '/' || c == '^') {
- switch (c) {
- case '+':
- printf("%d\n", a + b);
- break;
- case '-':
- printf("%d\n", a - b);
- break;
- case '*':
- printf("%d\n", a * b);
- break;
- case '/':
- if (b != 0) printf("%d\n", a / b);
- else printf("%d\n", 0);
- break;
- case '^':
- if (b >= 0) printf("%d\n", power(a, b));
- else printf("%d\n", 1);
- break;
- }
- }
- else printf("Unknown operation\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement