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

随机数计算小学四则运算

时间:2015-03-06 18:28:07      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

今天上课时老师布置我们计算随机数的四则运算,在二十分鈡的时间里我无法完成,在寒假里玩的太多了,知识都忘得差不多了,在这里我先用time函数,确保随机数生成的不会相同,为了让随机数都是两位数,我用了rand%90+10,使生成的都是两位数,用rand%5随机生成加减乘除,下面是源代码:

#include<iostream>
#include<ctime>
#include <cstdlib>
using namespace std;
void main()
{
int a, b,d, c;
srand(time(NULL));
for (c=1; c <31; c++)
{
a = rand() % 90+10;
b = rand() % 90+10;
d = rand() % 5;
if (d == 1)
cout << "NO." << c << " " << a << " + " << b << " = " << endl;
if (d == 2)
cout << "NO." << c << " " << a << " - " << b << " = " << endl;
if (d == 3)
cout << "NO." << c << " " << a << " * " << b << " = " << endl;
if (d == 4)
cout << "NO." << c << " " << a << " / " << b << " = " << endl;

}

 

随机数计算小学四则运算

标签:

原文地址:http://www.cnblogs.com/chengchengshuaio/p/4318721.html

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