四则运算

代码来源:http://www.cnblogs.com/m108280546/p/5269702.html

新增功能:可以自行循环

语言:C语言

编译环境:VC++6.0

运行环境:Windows

BUG:暂未发现BUG

GitHub地址:https://github.com/5Mei/calculate/blob/master/main.cpp

  #include<iostream.h>
 #include<stdio.h>
 #include<stdlib.h>
 #include<string.h>
 #include<time.h>
  
 char Operator()
 {
 char op;
 int i;
 i=rand()%4+1;
 switch(i)
 {
 case 1: return '+';
 case 2: return '-';
 case 3: return 'x';
 case 4: return '/';
 }
 }
  
 void integer()
 {
 int x,y;
 char op;
 x=rand()%100+1;
 y=rand()%100+1;
 op=Operator();
 if(op=='-')
 while(x<y)
 {
 x=rand()%100+1;
 y=rand()%100+1;
 }
 cout<<x<<op<<y<<"="<<endl;
 }
  
 void fraction()
 {
 int a,b,c,d;
 a=rand()%100+1;
 b=rand()%100+1;
 c=rand()%100+1;
 d=rand()%100+1;
 char op;
 while(a<=b||c<=d)
 {
 a=rand()%100+1;
 b=rand()%100+1;
 c=rand()%100+1;
 d=rand()%100+1;
 }
 op=Operator();
 if(op=='-')
 while((b*c-a*d)<0)
 {
 a=rand()%100+1;
 b=rand()%100+1;
 c=rand()%100+1;
 d=rand()%100+1;
 }
 cout<<b<<"/"<<a<<op<<d<<"/"<<c<<"="<<endl;
 }
  
 void main()
 {
 A:srand(time(0));
 int c,i,n,m;
 cout<< "请输入出题类型"<<endl;
 cout<< "1.整数四则运算"<<endl;
 cout<< "2.分数四则运算"<<endl;
 cin>>i;
 cout<< "请输入出题数目"<<endl;
 cin>>n;
 for(m=1;m<=n;m++)
 {
 if(i==1)
 integer();
 else
 fraction();
 }
 goto A;
  
 }

转载于:https://www.cnblogs.com/MeiT/p/7555063.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值