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

如果输入答案正确,则显示“Right!”,否则显示“Not correct!”,不给机会重做,10道题做完后,按每题10分统计总得分,然后打印出总分和做错的题目数量。

#include <stdafx.h>
#include <stdlib.h>
#include <conio.h> 
#include <time.h>
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();
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-05-17
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//'+','-','*','/'分别为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]<n[2])
{
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;
}
第2个回答  2017-08-01
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
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;
}

第3个回答  2017-08-21
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
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

第4个回答  2011-05-17
#include<stdlib.h>
#include<time.h>
//'+','-','*','/'分别为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]<n[2])
{
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;
相似回答