• 小学四则运算1.0


    //信1301-1班 张鹏宇 四则运算
    #include<iostream>
    #include<stdio.h>
    #include<time.h>
    using namespace std;
    
    void main(){
        int num1,num2,num3,num4;
        int a,b;
        int i;
        srand((unsigned)time(NULL));
    
        for(i=0;i<30;i++){   //30个
        b=rand()%2;      
        if(b==0){    //num1整数
            num1=rand()%101;
            b=rand()%2;
            if(b==0){   //num2整数
                num2=rand()%101;
                a=rand()%4;
                if(a==0)
                    cout<<num1<<"+"<<num2<<"="<<endl;
                if(a==1)
                    cout<<num1<<"-"<<num2<<"="<<endl; 
                if(a==2)
                    cout<<num1<<"*"<<num2<<"="<<endl;
                if(a==3){
                    if(num2==0){
                        for(;num2==0;)
                            num2=rand()%101;
                        cout<<num1<<"/"<<num2<<"="<<endl;
                    }
                    else
                        cout<<num1<<"/"<<num2<<"="<<endl;
                }
            }
            else{   //num2分数
                num2=rand()%101;
                num3=rand()%101;
                for(;num2>=num3;)
                    num3=rand()%102;
                for(;num3==0;)
                    num3=rand()%102;
                a=rand()%4;
                if(a==0)
                    cout<<num1<<"+"<<num2<<"/"<<num3<<"="<<endl;
                if(a==1)
                    cout<<num1<<"-"<<num2<<"/"<<num3<<"="<<endl;
                if(a==2)
                    cout<<num1<<"*"<<num2<<"/"<<num3<<"="<<endl;
                if(a==3){
                    if(num2==0){
                        for(;num2==0;)
                            num2=rand()%101;
                        cout<<num1<<"/"<<"("<<num2<<"/"<<num3<<")"<<"="<<endl;
                    }
                    else
                        cout<<num1<<"/"<<"("<<num2<<"/"<<num3<<")"<<"="<<endl;
                }
            }
        }
                        
                if(b==1){    //num1分数
                    num1=rand()%101;                
                    num2=rand()%101;
                    for(;num2==0;)
                        num2=rand()%101;
                    b=rand()%2;
                    if(b==0){     //num2整数
                        num3=rand()%101;
                        a=rand()%4;
                        cout<<num1<<"/"<<num2<<"+"<<num3<<"="<<endl;
                        if(a==1)
                            cout<<num1<<"/"<<num2<<"-"<<num3<<"="<<endl;
                        if(a==2)
                            cout<<num1<<"/"<<num2<<"*"<<num3<<"="<<endl;
                        if(a==3){
                            if(num3==0){
                                for(;num3==0;)
                                    num3=rand()%101;
                                cout<<num1<<"/"<<num2<<"+"<<num3<<"="<<endl;
                            }
                            else
                                cout<<num1<<"/"<<num2<<"+"<<num3<<"="<<endl;
                        }
                    }
                    else{     //num2分数
                        num3=rand()%101;
                        num4=rand()%101;
                        for(;num3>=num4;)
                            num4=rand()%102;
                        for(;num4==0;)
                            num4=rand()%102;
                        a=rand()%4;
                       if(a==0)
                           cout<<num1<<"/"<<num2<<"+"<<num3<<"/"<<num4<<"="<<endl;
                       if(a==1)
                           cout<<num1<<"/"<<num2<<"-"<<num3<<"/"<<num4<<"="<<endl;
                       if(a==2)
                           cout<<num1<<"/"<<num2<<"*"<<num3<<"/"<<num4<<"="<<endl;
                       if(a==3){
                           if(num3==0){
                               for(;num3==0;)
                                   num3=rand()%101;
                           }
                           else
                               cout<<"("<<num1<<"/"<<num2<<")"<<"/"<<"("<<num3<<"/"<<num4<<")"<<"="<<endl;
                       }
                    }
        }
        }
    }
  • 相关阅读:
    关于Linux联网的问题
    MapD的数据导出与扩容(利用现有的表)
    系统重启后,MapD报错Thrift的连接被拒绝
    关于Linux系统只读(Ubuntu16.4.1)
    javaBean的依赖注入中构造注入和依赖注入的区别
    Struts2开发中遇到的坑。。。
    通过配置文件设置定时任务,以及时间的选择
    微信小程序开发的movable开发的坑
    spring基础概念
    Hibernate的三种查询方式
  • 原文地址:https://www.cnblogs.com/fooreveryu/p/5242412.html
Copyright © 2020-2023  润新知