Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int read(void) {
- int n;
- printf("introduce a number: ");
- scanf("%d", &n);
- return n;
- }
- int max(int x, int y) {
- return x > y ? x : y;
- }
- int min(int x, int y) {
- return x > y ? y : x;
- }
- void printMenu(void) {
- puts("1) max");
- puts("2) min");
- puts("3) write x");
- puts("4) write y");
- puts("5) +");
- puts("6) -");
- puts("7) *");
- puts("8) /");
- puts("press anything else to quit");
- }
- int add(int x, int y) {
- return x + y;
- }
- int substract(int x, int y) {
- return x - y;
- }
- int multiply(int x, int y) {
- return x * y;
- }
- int divide(int x, int y) {
- return x / y;
- }
- void printRes(int res) {
- printf("result=%d\n", res);
- }
- int main(void) {
- int x, y, opt;
- x = read(), y = read();
- printMenu();
- opt = read();
- int res;
- switch(opt) {
- case 1:
- res = max(x, y);
- break;
- case 2:
- res = min(x, y);
- break;
- case 3:
- res = x;
- break;
- case 4:
- res = y;
- break;
- case 5:
- res = add(x, y);
- break;
- case 6:
- res = substract(x, y);
- break;
- case 7:
- res = multiply(x, y);
- break;
- case 8:
- res = divide(x, y);
- break;
- default:
- puts("Exiting...");
- return 0;
- }
- printRes(res);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement