课堂练习&课后作业

//四则运算
//2015.3.19
#include <iostream>
using namespace std;
void main()
{
    int i=0,j,k=0,n,m,l=0,p=0;
    int a[100],b[100],c[100];
    cout<<"请输入题目数:"<<endl;
    cin>>j;
    cout<<"是否有乘除法,若有则选1,没有则选2"<<endl;
    cin>>k;
    cout<<"数值范围(例:输入1 99 则数值范围为1-99):"<<endl;
    cin>>m>>n;
    if(k==1){
         cout<<"是否有负数,若有则选1,没有则选2"<<endl;
         cin>>l;
         cout<<"除法有无余数,若有余数则选1,没有则选2"<<endl;
         cin>>p;
         cout<<"输出的题目是:"<<endl;
         for(i=0;i<j;i++)
        {
             a[i]=rand()%(n-m+1)+m;
             b[i]=rand()%100;
             c[i]=rand()%(n-m+1)+m;
             if(b[i]>=0&&b[i]<=25)
                 cout<<a[i]<<"+"<<c[i]<<"=___"<<endl;
                 if(b[i]>=26&&b[i]<=50)
               {
                   if(l==1)
                  {
                      cout<<a[i]<<"-"<<c[i]<<"=___"<<endl;
                 }
                   else
               {
                     if(a[i]>c[i])
                         cout<<a[i]<<"-"<<c[i]<<"=___"<<endl;
                     else
                         cout<<c[i]<<"-"<<a[i]<<"=___"<<endl;
            }
        }
        if(b[i]>=51&&b[i]<=75)
            cout<<a[i]<<"*"<<c[i]<<"=___"<<endl;
        if(b[i]>=76&&b[i]<=100)
        {
            if(p==1)
            {
                 if(c[i]!=0)
                 cout<<a[i]<<"/"<<c[i]<<"=___"<<endl;
             else
             {
                 for(int y=0;;y++){
                 c[i]=rand()%(n-m+1)+m;
                 if(c[i]!=0)
                     break;
                 }
                 cout<<a[i]<<"/"<<c[i]<<"=___"<<endl;
             }
        }
            else
            {
                if(c[i]!=0&&a[i]%c[i]==0)
                    cout<<a[i]<<"/"<<c[i]<<"=___"<<endl;
                else
                {
                    for(int y=0;;y++){
                        a[i]=rand()%(n-m+1)+m;
                        c[i]=rand()%(n-m+1)+m;
                        if(c[i]!=0&&a[i]%c[i]==0)
                            break;
                    }
                    cout<<a[i]<<"/"<<c[i]<<"=___"<<endl;
                }
            }
        }
    }
     }
    else
    {
       cout<<"是否有负数,若有负数则选1,否则选2"<<endl;
       cin>>l;
       cout<<"输出的题目是:"<<endl;
       for(i=0;i<j;i++)
         {
             a[i]=rand()%(n-m+1)+m;
             b[i]=rand()%100;
             c[i]=rand()%(n-m+1)+m;
             if(b[i]>=0&&b[i]<=50)
                 cout<<a[i]<<"+"<<c[i]<<"=___"<<endl;
             if(b[i]>=51&&b[i]<=100)
             {
                 if(l==1)
                     cout<<a[i]<<"-"<<c[i]<<"=___"<<endl;
                 else
                 {
                     if(a[i]>c[i])
                         cout<<a[i]<<"-"<<c[i]<<"=___"<<endl;
                     else
                         cout<<a[i]<<"-"<<c[i]<<"=___"<<endl;
                 }
             }
    }
}
}
结果截图:
1.有乘除法,有负数,有余数。

2.
无乘除法,有负数。


3.
无乘除法,无负数。


4.
有乘除法,无负数,有余数。


5.
有乘除法,有负数,无余数。


6.
有乘除法,无负数,无余数。


posted @ 2016-03-26 17:46  沙漠绿鹰  阅读(154)  评论(0编辑  收藏  举报