首先通过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;
}
}