想法思路:(1)在1-100之内产生两个随机数,并且随机的进行四则运算;
(2)循环进行30次,产生30道题;
(3)二年级时,没有学到分数和负数,减数要小于或等于被减数。
源程序代码:
#include "stdafx.h"
#include"iostream.h"
#include"stdlib.h"
#include"math.h"
#include"time.h"
int main(int argc, char* argv[])
{
int a,b;
int m;
srand( (unsigned)time( NULL ) );
for(int i=1;i<=30;i++)
{
a=rand()%100;
b=rand()%100;
m=rand()%4;
switch(m)
{
case 0:
cout<<i<<" "<<a<<"+"<<b<<"="<<endl;
break;
case 1:
if(a>=b)
{
cout<<i<<" "<<a<<"-"<<b<<"="<<endl;
break;
}
case 2:
cout<<i<<" "<<a<<"x"<<b<<"="<<endl;
break;
case 3:
cout<<i<<" "<<a<<"/"<<b<<"="<<endl;
break;
}
}
return 0;
}
结果截图如下:
时间: 2024-10-24 17:54:13