用c语言做一个产生加法算术题的程序

2024-11-17 21:33:53
推荐回答(2个)
回答(1):

#include
#include
#include
void main()
{int i,j=0,a,b,c,sum=0,n;
srand((unsigned)time(NULL));
for(i=1;;i++)
{n=0; j++;
if(j==51)break;
if(i%2){printf("第%d题:",j);j--;}
if(i%2)a=rand()%10+1;
if(i%2==0)
{b=rand()%10+1;
loop:printf("%d+%d=",a,b);
scanf("%d",&c); n++;
if(c==a+b){printf("对了!\n");sum+=2;}
else if(n<2){printf("不对!");sum--;goto loop;}
else sum--;
}
}
printf("您总共得了%d分",sum);
}

回答(2):

main()
{
Sum(b,c) //构造一个函数
{
int a,b,c;
int i;
printf("%d + %d = ",b,c);
scanf("%d",a);
for(i = 0;i<= 1;i++)
{
if(a == 3)
printf("Right");
else
{
printf("Wrong!Please answer again.")
scanf("%d",a);
}
}
}

sum(2,3);
sum(3,5);
sum(2,9);
sum(7,5);
sum(8,5);
sum(1,9);
sum(2,6);
sum(8,5);
sum(3,3);
sum(3,8);
sum(2,4);
sum(3,5);
sum(2,7);
sum(7,5);
sum(4,6);
sum(8,9);
sum(7,6);
sum(7,9);
sum(4,9);
sum(8,6);

}

我没运行,我也是菜鸟!