用C语言 给小学生出加法考试题

2024-11-18 05:36:52
推荐回答(3个)
回答1:

#include
#include

int AddTest(int a,int b)
{
int answer;
printf("Please input the answer:");
scanf("%d",&answer);
if(answer==a+b){
printf("Right!\n");
return 1;}
else{
printf("Not correct!\n");
return 0;}
}

int main()
{
int i,j,k,m,sum=0,wsum=10;
for(k=0;k<10;k++){
i = rand()%10+1;
j = rand()%10+1;
printf("i=%d,j=%d\n",i,j);
m = AddTest(i,j);
sum+=m*10;
wsum-=m;
}
printf("The score is %d,and the wrong number is %d\n",sum,wsum);
return 0;
}
四则运算题可以产生随机数之后按其%4+1的结果来控制产生随机的四种运算,其他地方类似

回答2:

#include
#include
//设计这个东西的人在乱整
char* o="+-*/";
inline int Test(int a,int b){return a==b;}//这里也要用函数??
inline int max(int a,int b){return a>=b?a:b;}
inline int min(int a,int b){return a<=b?a:b;}
int main()
{
printf("%s","加减乘除四则运算测试!\n");
printf("%s","请在题目后面输入你的结果并按回车!(每题10分!)\n");
int i,mark=0;
for(i=0;i<10;i++)
{
//Generate:
int a,b;
time_t t;
time(&t);
srand(t);
a=rand()%10+1;
time(&t);
srand(t<>rand()*20);
b=rand()%10+1;
time(&t);
srand(t);
int ope=o[rand()%4];
int ans;
if(ope==o[0]){ ans=a+b;printf("%d+%d=?\n",a,b);}
else if(ope==o[1])
{
int ma=max(a,b),mi=min(a,b);
a=ma,b=mi;
ans=a-b;
printf("%d-%d=?\n",a,b);
}
else if(ope==o[2]){ ans=a*b;printf("%d*%d=?\n",a,b);}
else
{
while((a%b)) a=rand()%10+1,b=rand()%10+1;
ans=a/b;printf("%d/%d=?\n",a,b);
}
int input;
scanf("%d",&input);
mark+=Test(input,ans)?printf("Right!\n"),10:printf("Not correct!\n"),0;
}
printf("成绩:%d\n",mark);
return 0;
}
改进了:可以根据时间生成随机数

回答3:

?这是啥东西??