zoukankan      html  css  js  c++  java
  • 二柱子问题(随机产生四则运算题目)

    //随机输出30个四则运算式
    //2016/3/7;李营;20142930
    #include<iostream>
    using namespace std;

    void main()
    {

      int n;
      cout<<"请输入四则运算数的种类(1为整数,2为假分数):"<<endl;
      cin>>n;
      int a,b,c,d,y;
      for(int i=0;i<30;i++)
      {
        a=rand()%100;
        b=rand()%100;
        y=rand()%4;
        if(n==1)
        {
          if(b==0)
          {
            i--;
          }
          else
          {
            cout<<i+1<<": ";
            if(y==0)
            {
              cout<<a<<"+"<<b<<"="<<endl;
            }
            else if(y==1)
            {
              cout<<a<<"-"<<b<<"="<<endl;
            }
            else if(y==2)
            {
              cout<<a<<"*"<<b<<"="<<endl;
            }
            else
            {
              cout<<a<<"/"<<b<<"="<<endl;
            }
           }
        }
        else if(n==2)
        {
          c=rand()%100;
          d=rand()%100;
            if(b>=a||d>=c)
          {
            i--;
          }
          else
          {
            cout<<i<<": ";
            if(y==0)
            {
                cout<<"("<<a<<"/"<<b<<")+("<<c<<"/"<<d<<")="<<endl;
            }
            else if(y==1)
            {
                cout<<"("<<a<<"/"<<b<<")-("<<c<<"/"<<d<<")="<<endl;
            }
            else if(y==2)
            {
                cout<<"("<<a<<"/"<<b<<")*("<<c<<"/"<<d<<")="<<endl;
            }
            else
            {
                cout<<"("<<a<<"/"<<b<<")/("<<c<<"/"<<d<<")="<<endl;
            }
          }
        }

    }
      

  • 相关阅读:
    Entityframework的简单应用
    vs2012搭建gtest环境
    Just Me
    git简洁命令列表
    自定义控件(3)
    自定义控件(2)
    自定义控件(1)- 标签页
    使用AppleScript实现一个批量添加文件前缀的功能
    Win10下Wifi不能自动连接的问题
    Android利用Ksoap2调用Webservice时接收参数为空的问题
  • 原文地址:https://www.cnblogs.com/liying123/p/5251489.html
Copyright © 2011-2022 走看看