zoukankan      html  css  js  c++  java
  • 小学四则运算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;
                       }
                    }
        }
        }
    }
  • 相关阅读:
    第二周进度条博客
    软件工程个人作业01
    动手动脑1
    构建之法阅读笔记06
    构建之法阅读笔记05
    构建之法阅读笔记04
    poj 1631 LIS
    poj 1609 dp
    lightoj 1198 最大权重匹配
    hdu4696 想法题
  • 原文地址:https://www.cnblogs.com/fooreveryu/p/5242412.html
Copyright © 2011-2022 走看看