该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
void Menu(void)
{
printf("1,加法 2,减法 3,乘法 4,除法 5,退出\n");
printf("请选择题目类型:");
}
int Plus(void)
{
int a, b;
a = rand() % 10 + 1;
b = rand() % 10 + 1;
printf("%-2d + %-2d = ", a, b);
return a + b;
}
int Sub(void)
{
int a, b;
a = rand() % 10 + 1;
b = rand() % 10 + 1;
printf("%-2d - %-2d = ", a, b);
return a - b;
}
int Mult(void)
{
int a, b;
a = rand() % 10 + 1;
b = rand() % 10 + 1;
printf("%-2d * %-2d = ", a, b);
return a * b;
}
int Div(void)
{
int a, b;
while(a % b != 0)
{
a = rand() % 10 + 1;
b = rand() % 10 + 1;
}
printf("%-2d / %-2d = ", a, b);
return a / b;
}
int Subject(int type)
{
switch(type)
{
case 1: return Plus();
case 2: return Sub();
case 3: return Mult();
case 4: return Div();
}
}
void Do(int type)
{
int count = 0, score = 0, key, answer;
while(count
{
key = Subject(type);
scanf("%d", &answer);
if(key == answer)
score += 10;
count++;
}
printf("%d\n", score);
}
int main(void)
{
int type, score;
while(1)
{
Menu();
scanf("%d", &type);
if(type == 5) return 0;
Do(type);
system("pause");
system("cls");
}
}
这个程序定义了一个菜单,用户可以选择进行加法、减法、乘法或除法的随机数学题,并进行答题。程序会生成两个1到10之间的随机数,根据用户选择的操作进行计算并显示结果,然后用户输入答案,程序会检查答案是否正确并累计得分。程序运行直至用户选择退出。
2891

被折叠的 条评论
为什么被折叠?



