四则运算1

 

 

 作业要求:像二柱子那样,花二十分钟写一个能自动生成小学二年级四则运算题目的 “软件”。和同学们比较一下各自程序的功能、实现方法的异同等等。

编程源代码:

#include <iostream.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
int i = 0;
srand((unsigned)time(NULL)); 
while(i<30)
{

int a = rand()%100; 
int b = rand()%100;
int j;
j = rand()%4; 
cout<<a;
switch(j)
{
case 0:
cout<<"+";
break;
case 1:
cout<<"-";
break;
case 2:
cout<<"*";
break;
case 3:
cout<<"/";
break;
}
cout<<b<<"= ";
i++;
if(i%5==0)
cout<<endl;
}

return 0;
}

运行结果:

 

 

 

posted @ 2018-10-06 10:27  皇后大道东  阅读(104)  评论(0编辑  收藏  举报