首页 > 其他 > 详细

四则运算

时间:2015-03-06 21:56:17      阅读:217      评论:0      收藏:0      [点我收藏+]

首先通过rand()函数随机的输出两个数字,定义一个字符串数组,同样通过随机函数输出加,减,乘,除。外加一个循环输出30组四则运算

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include<time.h>
int main()
{
using namespace std;
srand(time(NULL));
for(int i=1;i<=30;i++)
{
int a=rand()%100;
int b=rand()%100;
string str[4]={"+","-","*","%"};
int d=rand()%4;
cout<<"("<<i<<")"<<a<<str[d]<<b<<"="<<endl;
}

}

技术分享

 

四则运算

原文:http://www.cnblogs.com/shishi1993-/p/4319271.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!