c语言实验报告1
- 格式:doc
- 大小:30.47 KB
- 文档页数:17
C语言程序设计报告
日
程序主要内容
任务1. 程序首先随机产生一到十之间的正整数,在屏幕上打印出问题,例如6*7=?然后让学生输入答案,序检查学生输入的答案是否正确,若正确,则“RIGHT”,然后问下一个问题,否则打印“WRONG,PLEASE TRY AGAIN”,然后提示学生重做,直到答对为止。
程序如下:
#include
#include
#include
int Magic(int x);
int Answer();
main()
{
int guess,answer,counter=1;
do{
printf("%d*%d=",Magic(1),Magic(2));
answer=Magic(1)*Magic(2);
if(Answer()==answer)
{
printf("Right\n");
break;
}
else
printf("Wrong!,please try again\n");
}while(counter>=1);
}
int Magic(int m)
int x,int y;
srand(time(NULL));
x=rand()%10+1;
y=rand()%10+1;
if(m==1) return x;
if(m==2) return y;
}
int Answer()
{
int n;
scanf("%d",&n);
return n;
}
任务2:在(1)的基础上,当学生回答错误时,最多给三次重做的机会。
:程序如下:
#include
#include
#include
int Magic(int x);
int Answer();
int Exam();
main()
{
int n;
n=Exam();
if(n==0) printf("Right\n");
else if(n==1) printf("Wrong!You have tried
three times!Test over\n ");
}
int Magic(int m)
{
int x,int y;
srand(time(NULL));
x=rand()%10+1;
y=rand()%10+1;
if(m==1) return x;
if(m==2) return y;
}
int Answer()
{
int n;
scanf("%d",&n);
return n;
}
int Exam()
{
int guess,answer,counter=1;
do{
printf("%d*%d=",Magic(1),Magic(2));
answer=Magic(1)*Magic(2);
counter++;
if(Answer()==answer)
return 0;
else if(counter<=3)
printf("Wrong! please try again\n");
}while(counter<=3); return 1;
任务3:在(1)的基础上,连续做10道乘法运算题,不给机会重做,若学生回答正确,提示“RIGHT”,否则提示“WRONG”,并按每题10分输出总分,再输出正确概率。程序如下:
#include
#include
#include
int Magic(int x);
int Answer();
int Exam();
main()
{
printf("rate=%d%%\n",E xam());
}
int Magic(int m)
{
int x,int y;
srand(time(NULL));
x=rand()%10+1;
y=rand()%10+1;
if(m==1) return x;
if(m==2) return y;
}
int Answer()
{
int n;
scanf("%d",&n);
return n;
}
int Exam()
{
int
answer,counter=1;
int i=0;
do
{
printf("%d*%d=",Magi c(1),Magic(2));
answer=Magic(1)*Magi c(2);
counter++;
if(Answer()==answer)
{
printf("Right!\n");
i++;
}
else
printf("Wrong!\n");