这个程序是给出复杂的四则运算,包含两个运算符的。
#include<stdio.h> int sum = 0; struct NUM3 { int one; int two; int three; int result; }stu2[400]; int complex(); int show() { printf("谢谢使用"); } void main() { int a=1; while (a == 1) { a = complex(); } show(); } int complex() { int a, b, c,m; int s[10]; for (int i = 0; i < 10; i++) { a = stu2[sum].one = rand() % 10 + 1; b = stu2[sum].two = rand() % 10 + 1; c = stu2[sum].three = rand() % 10 + 1; int n = rand() % 4 + 1;//stu2[sum].result = a*b + c; switch (n) { case 1: stu2[sum].result = a*b + c; printf("%d*%d+%d=\t", a, b, c); break; case 2: stu2[sum].result = a + b * c; printf("%d+%d*%d=\t", a, b, c); break; case 3: stu2[sum].result = a*b - c; printf("%d*%d-%d=\t", a, b, c); break; case 4: stu2[sum].result = a - b * c; printf("%d-%d*%d=\t", a, b, c); break; } sum = sum + 1; } printf("请输入上面十题的答案\n"); for (int i = 0; i < 10; i++) { printf("%d.",i+1); scanf_s("%d",&s[i]); } for (int i = 0; i < 10; i++) { if (s[i] == stu2[i].result) { printf("√"); } else{ printf("第%d题错误,正确答案是%d", i+1, stu2[i].result); } } printf("继续请按1,结束请按任意键"); scanf_s("%d",&m); if (m == 1) return 1; else return 0; }
下面是程序运行截图:
时间: 2024-12-28 11:33:22