#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
int main()
{
int a, x, y;
int total=0,right=0,mistake=0;
srand(time(0));
printf("输入esc退出,查看正确率.\n");
while
(x = rand() % 100 + 1,
y = rand() % 100 + 1,
printf("x=%2d ", x),
printf("y=%2d\n", y),
printf("请计算x+y="),
scanf("%d", &a))
{
if (x + y == a)
{
printf("恭喜你答对了!\n\n");
total=total+1;
right=right+1;
}
while的简单用法我知道,但是在这个程序里是什么原因?并且运行正确,什么原理?
if (x+y!=a){
printf("很遗憾,答错了.\n\n");
total=total+1;
mistake=mistake+1;
}
}
printf("total=%d\n",total);
printf("right=%d\n",right);
printf("mistake=%d\n",mistake);
return 0;
}
#include<stdlib.h>
#include<time.h>
#include<math.h>
int main()
{
int a, x, y;
int total=0,right=0,mistake=0;
srand(time(0));
printf("输入esc退出,查看正确率.\n");
while
(x = rand() % 100 + 1,
y = rand() % 100 + 1,
printf("x=%2d ", x),
printf("y=%2d\n", y),
printf("请计算x+y="),
scanf("%d", &a))
{
if (x + y == a)
{
printf("恭喜你答对了!\n\n");
total=total+1;
right=right+1;
}
while的简单用法我知道,但是在这个程序里是什么原因?并且运行正确,什么原理?
if (x+y!=a){
printf("很遗憾,答错了.\n\n");
total=total+1;
mistake=mistake+1;
}
}
printf("total=%d\n",total);
printf("right=%d\n",right);
printf("mistake=%d\n",mistake);
return 0;
}