#include"stdio.h"
#include"time.h" /* 定义随机数发生器头文件 */
#include"conio.h" /* 定义清屏函数 */
#include "stdlib.h" /* 定义随机数函数 */
void account(); /* 声明cccount函数 */
void mize(); /* 声明随机数函数 */
int a,b,c,d,e,k,g,h,j=0;
void mize()
{ randomize( ); /* 初始化随机数发生器 */
a=rand()/1000; /* 除1000使随机数变小 */
b=rand()/1000;
c=rand()/1000;
d=rand()/1000;
}
unsigned char t;
main()
{
int n;
while(1)
{
clrscr( );
printf(" ***************************************************\n");
printf(" Arithmetic Exercise System of Pupil\n");
printf(" ***************************************************\n");
printf(" 1.Addition Exercise\n");
printf(" 2.Subtract Exercise\n");
printf(" 3.Multiplication Exercise\n");
printf(" 4.Division Exercise\n");
printf(" 0.Quit\n");
printf("Choice(0--4):");
while(scanf("%d",&n)!=1) /* 判断输入是否为真0-4 */
{
while(getchar()!='\n'); /* 空格进行清屏 */
clrscr( );
printf("you input is wrong!\n"); /* 提示输入有误 */
puts("please input a right number:\n");
}
if(n>=0&&n<=4)
{
clrscr( );
switch(n) /* 如果匹配0-4则进行运行 */
{
case 0:
return 0;
z: case 1:
account(); printf("\n");
f1: printf("\nContinue(Y/N)?"); /* 定义显示Continue (Y/N)? */
t=getch();
printf("you input is %c\n",t);
if(!((t=='N'||t=='n')||(t=='Y'||t=='y')))
goto f1; /* 循环f1,以确定每次计数结束后还回Continue (Y/N)? */
if(t=='Y'||t=='y')
{clrscr( ); goto z;}
else
j=0;break;
p: case 2:
account(); printf("\n");
f3:
printf("\nContinue(Y/N)?");
t=getch();
printf("you input is %c\n",t);
if(!((t=='N'||t=='n')||(t=='Y'||t=='y')))
goto f3;
if(t=='Y'||t=='y')
{clrscr( ); goto p;}
else j=0; break;
x: case 3:
account(); printf("\n");
f2:
printf("\nContinue(Y/N)?");
t=getch();
printf("you input is %c\n",t);
if(!((t=='N'||t=='n')||(t=='Y'||t=='y')))
goto f2;
if(t=='Y'||t=='y') {clrscr( ); goto x;}
else
close();
u: case 4:
account(); printf("\n"); /* 调用account()函数 */
f:
printf("\nContinue(Y/N)?");
t=getch();
printf("you input is %c\n",t);
if(!((t=='N'||t=='n')||(t=='Y'||t=='y')))
goto f;
if(t=='Y'||t=='y')
{clrscr( ); goto u;}
else
j=0; break;
}
}
}
getch();
}
int add,sub,Mul,Div,t1,s,i=0;
void account(int n) /* 定义account 函数 */
{
mize();
while(1)
{
switch(n)
{
case 1:
printf("%d+%d=",a,b);scanf("%d",&e);
add=a+b; /* 定义加法运算 */
t1=e; /* 将答案赋给t1,以判断输入答案是否正确 */
s=a+b; /* 以确定运行3次后能给出题目答案 */
break;
case 2:
if(a>b) /* 确保不会出现负数 */
printf("%d-%d=",a,b);scanf("%d",&k);
sub=a-b;
t1=k;
s=a-b;break;
case 3:
printf("%d*%d=",c,d);scanf("%d",&g);
Mul=c*d;
t1=g;s=Mul;break;
case 4:
if(a/b!=0)
printf("%d/%d=",a,b);scanf("%d",&h);
Div=b/a;
t1=h;
s=b/a;break;
}
if(i<4)
{
if(t1==s&&i==1)
{
printf("OK !Very Good!\n");
break;
}
else if(t1==s&&i==2)
{
printf("OK! Good!\n");
break;
}
else if(t1==s&&i==3)
{
printf("OK!");
break;
}
else
{
clrscr( );
printf("Wrong! Do it again\n");
if(i==2)
{
clrscr( );
printf("Wrong! The right answer is: %d\n",s);
break;
}
i++; /* 每次运算完自动加1,以确定是否运行够3次 */
}
}
}
}
一则可以随机产生四则运算的c程序!
需积分: 38 73 浏览量
2009-03-08
02:07:09
上传
评论 5
收藏 1KB RAR 举报
fww_fww
- 粉丝: 1
- 资源: 1
最新资源
- 基于yolov5识别算法实现的DNF自动脚本源码.zip
- 基于Python实现的自动化办公项目.zip
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈