#include#include #include int free_num() //随机产生十以内的数字 { int num; num = rand() % 10 + 1; return num; } char free_word() //随机产生一个运算符 { int i = 0; char word = 'w'; int num = 0; i = rand() %4 + 1; switch (i) { case(1):word = '+'; return word; case(2):word = '-'; return word; case(3):word = '*'; return word; case(4):word = '/'; return word; } } int main() { srand((unsigned)time(NULL)); int a, b; char c; int ans = 0; int n = 0; int j = 0; int ret = 0; int ok = 0; printf("请输入你想回答的题数:n"); scanf_s("%d", &j); while (n < j) { a = free_num(); b = free_num(); c = free_word(); printf("%d %c %d", a, c, b); switch (c) { case '+':ans = a + b; break; case '-':ans = a - b; break; case '*':ans = a * b; break; case '/':ans = a / b; break; } printf("n"); printf("请回答你的答案:"); scanf_s("%d", &ret); if (ret == ans) { printf("you are rightn"); ok++; } else printf("you are non"); n++; } printf("你回答正确的题数是:"); printf("%d", ok); return 0; }
有用就点个赞呗
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)