小学四则运算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;
       }
    }
  
 }
}

}}

你可能感兴趣的:(小学四则运算1.0)