#include <stdio.h>
void addition(int x1, int x2){
int addition = x1 + x2;
printf("This is your result: %d\\n", addition);
}
void multiplication(int m1, int m2){
int multiplication = m1 * m2;
printf("This is your result: %d\\n", multiplication);
}
void division(int d1, int d2){
int division = d1/d2;
printf("This is your result: %d\\n", division);
}
void subtraction(int s1, int s2){
int subtraction1 = s1 - s2;
int subtraction2 = s2 -s1;
int ui;
printf("Do you want to print your numbers in postive or negative?\\n");
printf("Postive = 1\\n");
printf("Negative = 2\\n");
scanf("%d", &ui);
if (subtraction1 < 0){
printf("This is your result: %d\\n", subtraction2);
}else{
printf("This is your result: %d\\n", subtraction1);
}
}
int main() {
int operator;
int one, two;
printf("Multiplication = 1\\n");
printf("Division = 2\\n");
printf("Addition = 3\\n");
printf("Subtraction = 4\\n");
printf("Choose what kind of operator function you want to use?: ");
scanf("%d", &operator);
printf("Type Two Numbers to use the operator: ");
scanf("%d, %d", &one, &two);
switch (operator) {
case 1:
multiplication(one, two);
break;
case 2:
division(one, two);
break;
case 3:
addition(one, two);
break;
case 4:
subtraction(one, two);
break;
default:
printf("Please put valid operators from the choices above. :)");
break;
}
}
Each arithmetic operation has its function in the code, and the primary function uses a switch statement to call the appropriate function based on the user's selection. The subtraction function has an additional feature that asks the user if they want the result printed as a positive or negative number.