本文主要是介绍C语言程序设计苏小红课后习题答案7.14.4,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
//生成随机符号
char Charop()
{int op;op = rand() % 4 + 1;switch (op){case 1:return '+';case 2:return '-';case 3:return '*';case 4:return '/';}return 0;
}
//相关计算
int Calculate(int x, char op, int y)
{int a, b, c, d;a = x + y;b = x - y;c = x * y;d = x / y;switch (op){case '+': return a;case '-': return b;case '*': return c;case '/': return d;default:return 0;}
}
//输出运算
int fun()
{int answer, counter = 0, grade = 0;int x, y, m, n;char op;for (int i = 1;i <= 10;i++){op = Charop();srand(time(NULL));x = rand() % 10 + 1;y = rand() % 10 + 1;printf("%d%c%d=", x, op, y);scanf("%d", &answer);if (answer == Calculate(x, op, y)){printf("Right!\n");grade++;}elseprintf("Wrong!\n");counter++;}printf("grade=%d\n", grade);printf("Scoring rate=%d%%", grade * 10);
}
//主函数
int main()
{fun();return 0;
}
这篇关于C语言程序设计苏小红课后习题答案7.14.4的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!