课堂总结

实验题目:随机产生30道100以内的四则运算

思路:用rand产生两个随机数,然后用rand产生1.2.3.4代表加减乘除。之后输出。

代码:

#include<iostream>
using namespace std;
void main()
{
int a,b,c,n=30;


for(n=0;n<30;n++)
{
a=rand()%100+1;
b=rand()%100+1;
c=rand()%4+1;

if(c==1)
cout<<a<<"+"<<b<<"="<<endl;
if(c==2)
cout<<a<<"-"<<b<<"="<<endl;
if(c==3)
cout<<a<<"*"<<b<<"="<<endl;
if(c==4)
cout<<a<<"/"<<b<<"="<<endl;
}
}

问题:为什么课上没有做出?

当时rand不知道如何用(a=rand()%100+1),没想到如何表示加减乘除。

原文地址:https://www.cnblogs.com/double1/p/4319014.html