给小学生出加法考试题
#include<stdio.h>#include<stdlib.h>#include<time.h>voidmain(){inta,b,i,answer,sum,fen...
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{int a,b,i,answer,sum,fenshu=0,cuo=0;
int suiji();
for(i=0;i<10;i++)
{a=suiji();
b=suiji();
sum=a+b;
printf("%d+%d=",a,b);
scanf("%d",&answer);
if(sum==answer)
{printf("right!");
fenshu+=10;
}
else {printf("wrong!");cuo++;}
}
printf("your score is %3d,%d wrong",fenshu,cuo);
}
int suiji()
{int a;
srand(time(0));
a=rand()%10+1;
return(a);
}
a和b的值总是一样的,怎么可以解决这个问题 展开
#include<stdlib.h>
#include<time.h>
void main()
{int a,b,i,answer,sum,fenshu=0,cuo=0;
int suiji();
for(i=0;i<10;i++)
{a=suiji();
b=suiji();
sum=a+b;
printf("%d+%d=",a,b);
scanf("%d",&answer);
if(sum==answer)
{printf("right!");
fenshu+=10;
}
else {printf("wrong!");cuo++;}
}
printf("your score is %3d,%d wrong",fenshu,cuo);
}
int suiji()
{int a;
srand(time(0));
a=rand()%10+1;
return(a);
}
a和b的值总是一样的,怎么可以解决这个问题 展开
2个回答
展开全部
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void main()
{int a,b,i,answer,sum,fenshu=0,cuo=0;
int suiji();
for(i=0;i<10;i++)
{srand(time(NULL));
a=rand()%10+1;
b=rand()%10+1;
sum=a+b;
printf("%d+%d=",a,b);
scanf("%d",&answer);
if(sum==answer)
{printf("right!");
fenshu+=10;
}
else {printf("wrong!");cuo++;}
}
printf("your score is %3d,%d wrong",fenshu,cuo);
}
#include<stdlib.h>
#include<time.h>
void main()
{int a,b,i,answer,sum,fenshu=0,cuo=0;
int suiji();
for(i=0;i<10;i++)
{srand(time(NULL));
a=rand()%10+1;
b=rand()%10+1;
sum=a+b;
printf("%d+%d=",a,b);
scanf("%d",&answer);
if(sum==answer)
{printf("right!");
fenshu+=10;
}
else {printf("wrong!");cuo++;}
}
printf("your score is %3d,%d wrong",fenshu,cuo);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询