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

四则运算

时间:2017-04-13 23:35:46      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:color   ase   nbsp   code   and   定义   break   clu   opera   

// text.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include<iostream>
using namespace std;
#define size 10
char operation[4] = { +,-,*,/ };
int oper_[4], number_[10];
void IntAndInt()
{
    for (int i = 0; i < 4; i++)
        oper_[i] = rand() % 4;
    for (int j = 0; j < 5; j++)
        number_[j] = 1 + rand() % 10;
    cout << number_[0] << operation[oper_[0]] << number_[1] << operation[oper_[1]] << number_[2] << operation[oper_[2]] << number_[3] << operation[oper_[3]] << number_[4] << endl << endl;
}
void IntAndFloat()
{
    for (int i = 0; i < 4; i++)
        oper_[i] = rand() % 4;
    for (int j = 0; j < 7; j++)
        number_[j] = 1 + rand() % 10;
    cout << "(" << number_[0] << "/" << number_[1] << ")" << operation[oper_[0]] << number_[2] << operation[oper_[1]] << "(" << number_[3] << "/" << number_[4] << ")" << operation[oper_[2]] << number_[5] << operation[oper_[3]] << number_[6] << endl << endl;
}
void FloatAndFloat()
{
    for (int i = 0; i < 4; i++)
        oper_[i] = rand() % 4;
    for (int j = 0; j < 10; j++)
        number_[j] = 1 + rand() % 10;
    cout << "(" << number_[0] << "/" << number_[1] << ")" << operation[oper_[0]] << "(" << number_[2] << "/" << number_[3] << ")" << operation[oper_[1]] << "(" << number_[4] << "/" << number_[5] << ")" << operation[oper_[2]] << "(" << number_[6] << "/" << number_[7] << ")" << operation[oper_[3]] << "(" << number_[8] << "/" << number_[9] << ")" << endl << endl;
}
int main()
{
    int operation_type[size], i;
    for (i = 0; i < size; i++)
        operation_type[i] = rand() % 3;
    for (i = 0; i < size; i++)
        switch (operation_type[i])
        {
        case 0:FloatAndFloat(); break;
        case 1:IntAndFloat(); break;
        case 2:IntAndInt(); break;
        }
}

 

四则运算

标签:color   ase   nbsp   code   and   定义   break   clu   opera   

原文地址:http://www.cnblogs.com/ZJJ644758437/p/6706709.html

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