产生四则运算

#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<algorithm>
using namespace std;
int main()
{
    int k;
    long int a,b,t;
    cin>>k;
    srand(time(NULL));
    for(int i=0;i<k;i++)
    {
        a=rand()%100;
        b=rand()%100;
        t=rand()%4;
        switch(t)
        {
        case 0:
            cout<<a<<"+"<<b<<"="<<endl;
            break;
        case 1:
            if(a<b)
            {
               int temp;
               temp=a;
               a=b;
               b=temp;
            }
            cout<<a<<"-"<<b<<"="<<endl;
            break;
        case 2:
            cout<<a<<"*"<<b<<"="<<endl;
            break;
        case 3:
            if(b!=0)
            {
                cout<<a<<"/"<<b<<"="<<endl;
            }

        }
    }
}

 

posted @ 2018-03-08 09:07  sfcard  阅读(206)  评论(0编辑  收藏  举报