Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- int addition(int a, int b);
- int subtraction(int a, int b);
- int multiplication(int a, int b);
- int division(int a, int b);
- int modulo(int a, int b);
- int main(void) {
- char selection;
- int a, b, c;
- printf("Please select one of the following operations: \n"
- "a - addition\n"
- "s - subtraction\n"
- "m - multiplication\n"
- "d - division\n"
- "r - modulo\n"
- "Char: ");
- scanf("%c", &selection);
- if(selection == 'a') {
- printf("Enter a number: \n");
- scanf("%d", &a);
- printf("Enter another number: \n");
- scanf("%d", &b);
- c = addition(a ,b);
- printf("%d + %d = %d\n", a, b, c);
- }
- else if(selection == 's') {
- printf("Enter a number: \n");
- scanf("%d", &a);
- printf("Enter another number: \n");
- scanf("%d", &b);
- c = subtraction(a ,b);
- printf("%d - %d = %d\n", a, b, c);
- }
- else if(selection == 'm') {
- printf("Enter a number: \n");
- scanf("%d", &a);
- printf("Enter another number: \n");
- scanf("%d", &b);
- c = multiplication(a ,b);
- printf("%d * %d = %d\n", a, b, c);
- }
- else if(selection == 'd') {
- printf("Enter a number: \n");
- scanf("%d", &a);
- printf("Enter another number: \n");
- scanf("%d", &b);
- c = division(a ,b);
- printf("%d / %d = %d\n", a, b, c);
- }
- else if(selection == 'r') {
- printf("Enter a number: \n");
- scanf("%d", &a);
- printf("Enter another number: \n");
- scanf("%d", &b);
- c = modulo(a ,b);
- printf("%d r %d = %d\n", a, b, c);
- }
- else {
- printf("Wrong choice! Re-run program.\n");
- }
- }
- int addition(int a, int b) {
- int ans = a + b;
- return ans;
- }
- int subtraction(int a, int b) {
- int ans = a - b;
- return ans;
- }
- int multiplication(int a, int b) {
- int ans = a * b;
- return ans;
- }
- int division(int a, int b) {
- int ans = a / b;
- return ans;
- }
- int modulo(int a, int b) {
- int ans = a % b;
- return ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement