c语言小学生加法考试题 ,连续做10道题,通过计算机随机产生两个1~10之间的加数给学生出一道加法运算题程序

2024-12-26 16:03:18
推荐回答(5个)
回答1:

#include 
#include 
#include  
#include 
void main() 
{
int i,a,b,n,k=0;
for(i=1;i<=10;i++)
{
srand((unsigned int)time(0));
a=rand()%10+1;
b=rand()%10+1;
printf("%d+%d=",a,b);
scanf("%d",&n);
if(n==a+b)
{printf("Right!\n");k++;}
else printf("Not correct!\n");
}
printf("总分: %d\n做错题的数量: %d",k*10,10-k);
getch();
}

回答2:

#include
#include
#include
//'+','-','*','/'分别为43,45,42,47
int RightAnswer;
int jisuan(int n[3])
{
int answer,x;
printf("%d%c%d=",n[0],n[1],n[2]);
scanf("%d",&answer);
if(answer==RightAnswer)
{
printf("Right!\n");
x=10;
}
else
{
printf("Wrong!\n");
x=0;
}
return x;
}

int main()
{
int n[3];
int i=0,scord=0,temp;
for(i=0;i<10;i++)
{
srand(time(0));
n[0]=rand()%10+1;
n[1]=rand()%4;
n[2]=rand()%10+1;
switch(n[1])
{
case 0:
RightAnswer=n[0]+n[2];
n[1]='+';
break;
case 1:
if(n[0] {
temp=n[2];
n[2]=n[0];
n[0]=temp;
}
RightAnswer=n[0]-n[2];
n[1]='-';
break;
case 2:
RightAnswer=n[0]*n[2];
n[1]='*';
break;
case 3:
RightAnswer=n[0]/n[2];
n[1]='/';
n[0]=n[0]-n[0]%n[2];
break;
}
scord+=jisuan(n);
}
printf("总分为:%d,答错了%d道",scord,10-scord/10);
return 0;
}

回答3:

#include
#include
#include
int main(void){
unsigned int i,a,b;
srand((unsigned int)time(NULL));
for(i=0;i<10;i++)
{
a=rand()%10+1;
b=rand()%10+1;
printf("%d + %d = \n",a,b);
}
return 0;
}

回答4:

#include
#include
#include
int main(void)
{
    unsigned int i,a,b;
    srand((unsigned int)time(NULL));      
    for(i=0;i<10;i++)
    {  
        a=rand()%10+1;
        b=rand()%10+1; 
        printf("%d + %d = \n",a,b);
    }  
    return 0;
}//转自百度:https://zhidao.baidu.com/question/268920227

回答5:

#include
#include
//'+','-','*','/'分别为43,45,42,47
int RightAnswer;
int jisuan(int n[3])
{
int answer,x;
printf("%d%c%d=",n[0],n[1],n[2]);
scanf("%d",&answer);
if(answer==RightAnswer)
{
printf("Right!\n");
x=10;
}
else
{
printf("Wrong!\n");
x=0;
}
return x;
}

int main()
{
int n[3];
int i=0,scord=0,temp;
for(i=0;i<10;i++)
{
srand(time(0));
n[0]=rand()%10+1;
n[1]=rand()%4;
n[2]=rand()%10+1;
switch(n[1])
{
case 0:
RightAnswer=n[0]+n[2];
n[1]='+';
break;
case 1:
if(n[0] {
temp=n[2];
n[2]=n[0];
n[0]=temp;
}
RightAnswer=n[0]-n[2];
n[1]='-';
break;
case 2:
RightAnswer=n[0]*n[2];
n[1]='*';
break;
case 3:
RightAnswer=n[0]/n[2];
n[1]='/';
n[0]=n[0]-n[0]%n[2];
break;
}
scord+=jisuan(n);
}
printf("总分为:%d,答错了%d道",scord,10-scord/10);
return 0;