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;
                       }
                    }
        }
        }
    }
  • 相关阅读:
    js基础学习
    线程安全与锁
    JS浏览器检测工具方法、url参数读取
    【转载】JS时间工具类收藏(时间转换、倒计时)
    使用JQuery插件Jcrop进行图片截取
    记录小文件上传的几个例子(含进度条效果,附源码下载)
    T-SQL分页查询语句
    记录JavaScript中使用keyup事件做输入验证(附event.keyCode表)
    知识记录:ASP.NET 应用程序生命周期概述及Global.asax文件中的事件
    记录FormsAuthentication的使用方法
  • 原文地址:https://www.cnblogs.com/fooreveryu/p/5242412.html
Copyright © 2011-2022 走看看