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.
c-language/小学生测验最终版第三次修改.c

147 lines
2.4 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<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<math.h>
typedef struct node
{
int jiajian;
int num1;
int num2;
int trytimes;
}specific;
specific informat[10];
void changesi(int p)
{
if(p==0)
printf("+");
if(p==1)
printf("-");
}
int getgrade(int m)
{
if(m==0)
return 10;
if(m==1)
return 7;
if(m==2)
return 5;
if(m==3)
return 0;
}
int suijishu(int a,int b,int c,int t)
{
int a1,b1;
do
{
a1=rand()%50;
b1=rand()%50;
}while(!(a1+b1>=0&&a1+b1<+50&&a1-b1>=0&&a1-b1<=50));
informat[t].num1=a=a1;
informat[t].num2=b=b1;
informat[t].jiajian=c=rand()%2;
return 0;
}
void show_rank(int sum)
{
printf("\n\n");
printf("总分:%d\n",sum);
if(sum>=90)
printf("SMART\n");
else if(sum<90&&sum>=80)
printf("GOOD\n");
else if(sum<80&&sum>=70)
printf("OK\n");
else if(sum<70&&sum>=60)
printf("PASS\n");
else
printf("TRE AGAIN\n");
}
int main()
{
srand(time(NULL));
printf("----------pupil exercise system----------\n");
printf("\t\t\t*******************************************************\n");
printf("\t\t\t* 此次测试的题目有10道 *\n");
printf("\t\t\t* 题目类型为两位数的加减 *\n");
printf("\t\t\t* 每题10分总分为100分。 *\n");
printf("\t\t\t*******************************************************\n");
int t=1,cnt=0,sum=0,a,b,c,ans;
while(t<=10)
{
printf("this is the %d question\n",t);
suijishu(a,b,c,t);
while(cnt<=3)
{
if(c==0)
{
printf("%d+%d=",a,b);
scanf("%d",&ans);
if(a+b==ans)
{
printf("Right\n");
break;
}
else
{
cnt++;
printf("Wrong!!\n");
if(cnt==3)
{
printf("anwser is:%d\n",a+b);
break;
}
}
}
else if(c==1)
{
printf("%d-%d=",a,b);
scanf("%d",&ans);
if(a-b==ans)
{
printf("Right\n");
break;
}
else
{
cnt++;
printf("Wrong!!\n");
if(cnt==3)
{
printf("anwser is:%d\n",a-b);
break;
}
}
}
}
informat[t].trytimes=cnt;
if(cnt==0)
sum+=10;
if(cnt==1)
sum+=7;
if(cnt==2)
sum+=5;
t++;
cnt=0;
printf("\n\n");
printf("--------------------\n");
}
show_rank(sum);
printf("\n\n");
int i;
for(i=1;i<=10;i++)
{
printf("第%d题:%d",i,informat[i].num1);
changesi(informat[i].jiajian);
printf("%d=",informat[i].num2);
if(informat[i].jiajian==0)
printf("%d\n",informat[i].num1+informat[i].num2);
else if(informat[i].jiajian==1)
printf("%d\n",informat[i].num1-informat[i].num2);
printf("你错了%d次得了%d分\n",informat[i].trytimes,getgrade(informat[i].trytimes));
}
float p;
p=sum/10.0;
printf("你的正确率是:%.2f%%\n",p*10);
return 0;
}