四则运算

设计思路

1.随机产生三个数  

2.第二个数除以四产生余数

3.剩下两个数作运算

4.第二个数得到的余数用作对应出运算符

5.将三个依次输出

#include<iostream>

#include<string>

#include<time.h>

using namespace std;

 

int main()

{

    srand((unsigned)time(NULL));

    int a,b,c;

    string x;

    for (int i=0; i < 30; i++)

    {

        a = rand() % 100;

        b = rand() % 100;

        c = rand() % 4;

        switch (c)

        {

        case 0:x = "+"; break;

        case 1:x = "-"; break;

        case 2:x = "*"; break;

        case 3:x = "/";

        }

        cout << a << " " << x << " " << b+1 << " =" << "     ";

        if(i%3==0)

            cout<<endl;

    }

    system ("pause");

    return 0;

}

总结:对程序语言的掌握仍然需要提升

posted on 2018-10-08 13:52  数理小牛  阅读(623)  评论(0编辑  收藏  举报

导航