标签:
#include <stdlib.h>
#include <iostream>
#include <time.h>
using namespace std;
//随机产生30个四则运算题目的tesk
void tesk()
{
int x, y, z;
for (int i = 0; i < 30; i++){
x = rand() % 100;
y = rand() % 100;
z = rand() % 4;
switch (z)
{
case(0) :
cout << x << ‘+‘ << y <<‘=‘<< endl;
break;
case(1) :
cout << x << ‘-‘ << y <<‘=‘<< endl;
break;
case(2) :
cout << x << ‘*‘ << y <<‘=‘<< endl;
case(3) :
cout << x << ‘+‘ << y <<‘=‘<< endl;
default:
break;
}
}
}
//调用函数tesk
void main()
{
tesk();
system("pause");
}
此题目的难点在于rand函数(随机数产生器)的运用,然后用switch进行简单的选择,最后调用函数即可。
标签:
原文地址:http://www.cnblogs.com/huangxiaofei/p/4320434.html