Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int add(int a, int b) {
- return a + b;
- }
- int sub(int a, int b) {
- return a - b;
- }
- int mul(int a, int b) {
- return a * b;
- }
- float div(int a, int b) {
- return a / b;
- }
- int mod(int a, int b) {
- return a % b;
- }
- int power(int a, int b) {
- int res = 1;
- while (b != 0) {
- res *= a;
- b--;
- }
- return res;
- }
- int main() {
- int a, b, choice, result;
- while (true) {
- printf("1. Addition\n");
- printf("2. Subtraction\n");
- printf("3. Multiplicaton\n");
- printf("4. Division\n");
- printf("5. Modulus\n");
- printf("6. Power\n");
- printf("7. Exit\n");
- printf("Enter Your choice: ");
- scanf("%d", &choice);
- if (choice == 1) {
- printf("Enter two numbers: ");
- scanf("%d %d", &a, &b);
- result = add(a, b);
- printf("%d\n", result);
- } else if (choice == 2) {
- printf("Enter two numbers: ");
- scanf("%d %d", &a, &b);
- result = sub(a, b);
- printf("%d\n", result);
- } else if (choice == 3) {
- printf("Enter two numbers: ");
- scanf("%d %d", &a, &b);
- result = mul(a, b);
- printf("%d\n", result);
- } else if (choice == 4) {
- printf("Enter two numbers: ");
- scanf("%d %d", &a, &b);
- if (b != 0) {
- result = div(a, b);
- printf("%d\n", result);
- } else {
- printf("Divide by zero is not possible!\n");
- }
- } else if (choice == 5) {
- printf("Enter two numbers: ");
- scanf("%d %d", &a, &b);
- result = mod(a, b);
- printf("%d\n", result);
- } else if (choice == 6) {
- printf("Enter two numbers: ");
- scanf("%d %d", &a, &b);
- result = power(a, b);
- printf("%d\n", result);
- } else if(choice == 7) {
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement