码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算 改进

时间:2015-04-01 16:57:06      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void main()
{
int a,b,c,d;
int total1=0,total2=0;
while(1)
{
srand(time(NULL));
d=a=rand()%100;
b=(rand()%a+a)%100;
if(a%4==1&&a<b)c=a,a=b,b=c;
if(b==0&&a%4==3)b=rand()%10+1;
if(a%4==3&&a%b!=0)
{
srand(time(0));
a=b*(rand()%a);
}
switch(d%4)
{
case 0:printf("%d + %d = ",a,b);break;
case 1:printf("%d - %d = ",a,b);break;
case 2:printf("%d × %d = ",a,b);break;
case 3:printf("%d ÷ %d = ",a,b);break;
}
scanf("%d",&c);
switch(d%4)
{
case 0:if(c==a+b){printf("正确\n");total1++;}else {printf("错误\n");total2++;}break;
case 1:if(c==a-b){printf("正确\n");total1++;}else {printf("错误\n");total2++;}break;
case 2:if(c==a*b){printf("正确\n");total1++;}else {printf("错误\n");total2++;}break;
case 3:if(c==a/b){printf("正确\n");total1++;}else {printf("错误\n");total2++;}break;
}
printf("按任意键继续,Q退出!\n");
fflush(stdin);
if(getchar()==Q)break;
}
printf("你答对了%d道题,答错%d道题\n",total1,total2);
}

技术分享

四则运算 改进

标签:

原文地址:http://www.cnblogs.com/qq1076529919/p/4384120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!