首页 > 代码库 > 四则运算
四则运算
// 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; } }
四则运算
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。