第一节 课堂测试

20分钟内写一个100以内的随机四则用算

C++程序源代码:

#include<iostream>

#include<ctime>

using namespace std;

int main()

{  

int i,j,k;  

srand((unsigned) time(NULL));

 for(int a=0 ;a<30;a++)  

{  

 i=rand()%100;   

j=rand()%100;   

k=rand()%4;

  if (k==1)    

cout<<i<<"+"<<j<<"="<<endl;   

if (k==2)    

cout<<i<<"-"<<j<<"="<<endl;   

if (k==3)    

cout<<i<<"*"<<j<<"="<<endl;   

if (k==0)    

cout<<i<<"/"<<j<<"="<<endl;    

}  

return 0;

}

20分钟内没有完成是因为rand()函数不熟练,练习不多。

原文地址:https://www.cnblogs.com/D9412/p/4317987.html