Skip to content

Latest commit

 

History

History
124 lines (61 loc) · 2.07 KB

四则运算.md

File metadata and controls

124 lines (61 loc) · 2.07 KB

DianeBlue

//1301-2 20133056 吕兰兰 随机产生30道四则运算题目

#include

#include

using namespace std;

int main()

{

     int num_a,num_b,num_c,num_d;//随机产生4个1-100的整数

     double a,b;//用来表示真分数

     int c,d,e;//用来随机产生数字,c用来判断选择的是整数还是分数,d用来选择+-*/,e用来选择第二个数字是整数还是分数

     srand(time(0));

     for(int i=1;i<31;i++)

     {

               num_a=rand()%100+1;

         num_b=rand()%100+1;

         //求第一位真分数,产生的整数要比第一位整数小

         do

         {

                  num_c=rand()%100+1;

          }while (num_c>=num_a);

          a=num_c/num_a;

        //求第二位真分数,产生的整数要比第二位整数小

         do

         {

                  num_d=rand()%100+1;

          }while(num_d>=num_b);

     b=num_d/num_b;



         //选择第一位数字,为

          c=rand()%2+1;

    if(c==1)

         {

                  cout<<num_a<<" ";

          }

         if(c==2)

         {

                  cout<<"("<<num_c<<"/"<<num_a<<")"<<" ";

          }

         //产生四种运算符

          d=rand()%4+1;

          switch(d)

         {

                        case 1:cout<<"+ ";break;

                        case 2:cout<<"- ";break;

                        case 3:cout<<"* ";break;

                        case 4:cout<<"/ ";break;



               }

     //随机产生第二位的数字,可以为整数或分数

               e=rand()%2+1;

               if(e==1)

               {

                        cout<<num_b;

               }

               if(e==2)

               {

                        cout<<"("<<num_d<<"/"<<num_b<<")";

               }

               cout<<"=";

               cout<<endl;

               cout<<endl;

     }

}