课堂作业
思路:该题目要需要用随机数,所以要用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;
	}
}
当时不清楚随机数的产生方法,所以一时没完成作业。
 
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号