1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| #include <stdio.h> #include <stdlib.h>
void displayMenu() { system("cls"); printf(" 欢迎进入计算器\n "); printf("***************************\n "); printf("* 1.加法 *\n "); printf("* 2.减法 *\n "); printf("* 3.乘法 *\n "); printf("* 4.除法 *\n "); printf("* 5.求余 *\n "); printf("* 6.阶乘 *\n "); printf("* 7.累加 *\n "); printf("* 8.结束 *\n "); printf("***************************\n "); printf("请输入计算类型编号:"); }
int function(int e) { if (e == 1 || e == 0) return 1; else return e * function(e - 1); }
int main() { char user, y; int input, a = 0, b = 0; printf("是否进入计算器,y/n(是/否):"); scanf("%c", &user); if (user == 'y') displayMenu(); else if (user == 'n') exit(0); else { printf("输入有误,请重新输入"); exit(0); } scanf("%d", &input); system("cls");
switch (input) { case 1: { printf("请输入数据:"); scanf("%d%d", &a, &b); printf("%d+%d=%d\n", a, b, a + b); break; }
case 2: { printf("请输入数据:"); scanf("%d%d", &a, &b); printf("%d-%d=%d\n", a, b, a - b); break; } case 3: { printf("请输入数据:"); scanf("%d%d", &a, &b); printf("%d*%d=%d\n", a, b, a * b); break; } case 4: { printf("请输入数据:"); scanf("%d%d", &a, &b); printf("%d/%d=%d\n", a, b, a / b); break; } case 5: { printf("请输入数据:"); scanf("%d%d", &a, &b); printf("%d mold %d=%d\n", a, b, a % b); break; } case 6: { int e = 0; printf("请输入数据:"); scanf("%d", &e); printf("%d!=%d\n", e, function(e)); break; } case 7: { int result = 0; for (int i = 0; i < 1000; i++) { char input1; printf("退出请按任意键,计算请按M键:"); scanf("%s", &input1); if (input1 == 'M' || input1 == 'm') { int c, d; printf("请输入数据:"); scanf("%d%d", &c, &d); printf("result=%d\n", result += (c + d)); } else exit(0); } break; } case 8: { printf("谢谢使用,再见!"); exit(0); break; }
default: printf("error,please try again!!!"); } system("pause"); return 0; }
|