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

二柱子之随机四则运算

时间:2016-03-04 19:13:16      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

  1. //    2016-03-04 18:05:00
  2. //1.随机生成10以内的数为 a
  3. //2.以0代表‘+‘,1代表‘-‘,2代表‘*‘,3代表‘/‘ 随机生成4以内的数为 运算符
  4. //3.随机生成100以内的数为 b
  5. //4. a 运算符 b =
  6. //1.随机生成10以内的数 a
  7. //2.随机生成10以内的数 b
  8. //3.随机生成10以内的数 c
  9. //4.随机生成10以内的数 d
  10. //5.如果b不大于a 重复1 2  第一个真分数是a/b  第二个真分数是c/d
  11. //6.以1代表‘+‘,2代表‘-‘,3代表‘*‘,4代表‘/‘ 随机生成4以内的数为 运算符
  12. //7.a/b 运算符 c/d =
  13. #include<iostream>
  14. #include<ctime>
  15. using namespace std;
  16. int main()
  17. {
  18.  srand((unsigned)time(0));
  19.  for(int i=0;i<30;i++)
  20.  {
  21.   int a=rand()%10;
  22.   int b=rand()%10;
  23.   int c=rand()%4;
  24.   if(0==c) cout<<i+1<<". "<<a<<"+"<<b<<"="<<endl;
  25.   if(1==c) cout<<i+1<<". "<<a<<"-"<<b<<"="<<endl;
  26.   if(2==c) cout<<i+1<<". "<<a<<"*"<<b<<"="<<endl;
  27.   if(3==c) cout<<i+1<<". "<<a<<"/"<<b<<"="<<endl;
  28.  }
  29.  int j=0;
  30.  while(j<30)
  31.  {
  32.   int a=rand()%10;
  33.   int b=rand()%10;
  34.   if(a!=b)
  35.   {
  36.    int c=rand()%10;
  37.    int d=rand()%10;
  38.    if(c!=d)
  39.    {
  40.     int e=rand()%4;
  41.     if(0==e) cout<<j+1<<". "<<a<<"/"<<b<<" + "<<c<<"/"<<d<<"="<<endl;
  42.     if(1==e) cout<<j+1<<". "<<a<<"/"<<b<<" - "<<c<<"/"<<d<<"="<<endl;
  43.     if(2==e) cout<<j+1<<". "<<a<<"/"<<b<<" * "<<c<<"/"<<d<<"="<<endl;
  44.     if(3==e) cout<<j+1<<". "<<a<<"/"<<b<<" / "<<c<<"/"<<d<<"="<<endl;
  45.     j++;
  46.    }
  47.   }
  48.  }
  49. }
  50. 技术分享
  51. 技术分享

二柱子之随机四则运算

标签:

原文地址:http://www.cnblogs.com/L-Damon-v/p/5242995.html

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