首页 > 其他 > 详细

课堂作业

时间:2015-03-06 20:26:37      阅读:129      评论:0      收藏:0      [点我收藏+]

思路:该题目要需要用随机数,所以要用rand函数产生1-100随机数,在产生随机数1-4来表示加减乘除,最后用for循环执行30次。

代码:#include<iostream>
#include<time.h>

using namespace std;
void main()
{
int i,j,h,p;
for(p=0;p<30;p++)
{
i=rand()%100+1;
j=rand()%100+1;
h=rand()%4+1;
if(h==1)
cout<<i<<"+"<<j<<"="<<endl;
if(h==2)
cout<<i<<"-"<<j<<"="<<endl;
if(h==3)
cout<<i<<"*"<<j<<"="<<endl;
if(h==4)
cout<<i<<"/"<<j<<"="<<endl;
}
}

当时不清楚随机数的产生方法,所以一时没完成作业。

课堂作业

原文:http://www.cnblogs.com/bingoing/p/4319031.html

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