码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算

时间:2018-10-08 14:58:06      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:依次   掌握   system   src   srand   ==   分享   rand   bre   

设计思路

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;

}

技术分享图片

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

四则运算

标签:依次   掌握   system   src   srand   ==   分享   rand   bre   

原文地址:https://www.cnblogs.com/try-my--best/p/9753905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!