You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
srand(time(0));
printf("小学生测验\n");
int i,t,k=0,a,b,s=0;
for(i=0;i<10;i++)
{
a=rand()%51;
b=rand()%51;
while(a+b>50) //使k的最大值小于50
{
k=a+b;
if(k>50)
{
a=rand()%51;
b=rand()%51;
}
}
if(b<a) //如果b<a 使用加法。
{
k=b+a;
printf("%d+%d=",b,a);
scanf("%d",&t);
if(t==k) //学生第一次输入正确答案得10分。
{
s+=10;
}
else
{
printf("答案错误,请重新输入"); //学生第二次输入正确答案得7分。
scanf("%d",&t);
if(t==k)
{
s+=7;
}
else
{
printf("答案错误,请重新输入");
scanf("%d",&t);
if(t==k) //学生第三次输入正确答案得5分。
{
s+=5;
}
else //学生三次输入的答案都不正确得0分。
{
s+=0;
printf("正确答案为%d\n",k);
}
}
}
}
else
{
k=b-a; //如果b>a使用减法。
printf("%d-%d=",b,a);
scanf("%d",&t);
if(t==k) //学生第一次输入正确答案得10分。
{
s+=10;
}
else
{
printf("答案错误,请重新输入");
scanf("%d",&t);
if(t==k) //学生第二次输入正确答案得7分。
{
s+=7;
}
else
{
printf("答案错误,请重新输入");
scanf("%d",&t);
if(t==k) //学生第三次输入正确答案得5分。
{
s+=5;
}
else //学生三次输入的答案都不正确得0分。
{
s+=0;
printf("正确答案为%d\n",k);
}
}
}
}
}
printf("%d ",s); //输出该学生的最终成绩并给他评定级别。
if(s<60)
printf("TAY AGAAIN ");
else if(s>=60&&s<=70)
printf("PASS ");
else if(s>70&&s<=80)
printf("OK ");
else if(s>80&&s<=90)
printf("GOOD ");
else
printf("SMART ");
return 0;
}