#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int
i=0,j=0;
void
jia()
{
int
a,b,m;
srand(time(NULL));
a=1+rand()%100;
b=1+rand()%100;
printf(
"%d
"
,a);
printf(
"%d
"
,b);
printf(
"a+b=?
"
);
printf(
"请输入运算结果
"
);
scanf(
"%d"
,&m);
if
(m==a+b)
{
printf(
"恭喜你答对了
"
);
i++;
}
else
{
printf(
"你答案有错误
"
);
j++;
}
}
void
jian()
{
int
a,b,m;
srand(time(NULL));
a=1+rand()%100;
b=1+rand()%100;
if
(a<b)
{
int
t=0;
t=a;a=b;b=t;
}
printf(
"%d
"
,a);
printf(
"%d
"
,b);
printf(
"a-b=?
"
);
printf(
"请输入运算结果
"
);
scanf(
"%d"
,&m);
if
(m==a-b)
{
printf(
"恭喜你答对了
"
);
i++;
}
else
{
printf(
"你答案有错误
"
);
j++;
}
}
void
cheng()
{
int
a,b,m;
srand(time(NULL));
a=1+rand()%20;
b=1+rand()%20;
printf(
"%d
"
,a);
printf(
"%d
"
,b);
printf(
"a*b=?
"
);
printf(
"请输入运算结果
"
);
scanf(
"%d"
,&m);
if
(m==a*b)
{
printf(
"恭喜你答对了
"
);
i++;
}
else
{
printf(
"你答案有错误
"
);
j++;
}
}
void
chu()
{
int
a,b,m;
srand(time(NULL));
a=1+rand()%100;
b=1+rand()%100;
if
(b==0)
{
b=1+rand()%100;
}
if
(a<b)
{
int
t=0;
t=a;a=b;b=t;
}
while
(a%b!=0)
{
a=1+rand()%100;
b=1+rand()%100;
}
printf(
"%d
"
,a);
printf(
"%d
"
,b);
printf(
"a/b=?
"
);
printf(
"请输入运算结果
"
);
scanf(
"%d"
,&m);
if
(m==a/b)
{
printf(
"恭喜你答对了
"
);
i++;
}
else
{
printf(
"你答案有错误
"
);
j++;
}
}
<br>
int
main()
{
int
m,n=0;
while
(1)
{
printf(
"1.加法运算
"
);
printf(
"2.减法运算
"
);
printf(
"3.乘法运算
"
);
printf(
"4.除法运算
"
);
printf(
"请选择"
);
scanf(
"%d"
, &m);
switch
(m)
{
case
1:jia();
break
;
case
2:jian();
break
;
case
3:cheng();
break
;
case
4:chu();
break
;
}
printf(
"5.请重新选择
"
);
printf(
"6.结束
"
);
scanf(
"%d"
, &n);
if
(n==6)
break
;
}
printf(
"你回答题的总数%d和正确的个数%d
"
,i+j,i);
return
0;
}
加法运算界面
减法运算界面
乘法运算界面
除法运算界面
因为我的基础有限,所以自己写不出很严谨的运算程序,所以我借鉴了一下别的程序。做出了这套简单的四则运算程序!