标签:
问题
用程序实现随机编30道2年级四则运算题
源代码
#include<iostream.h>
#include<time.h>
#include<stdlib.h>
int main()
{
int a,b,c,d;
srand((int)time(0));
for(int i=0;i<30;i++)
{
a=1+(int)(100*rand()/(RAND_MAX+1.0));
b=1+(int)(100*rand()/(RAND_MAX+1.0));
c=1+(int)(4*rand()/(RAND_MAX+1.0));
if(c%4==0) cout<<"第"<<i+1<<"道:"<<a<<"/"<<b<<"="<<endl;
if(c%4==1) cout<<"第"<<i+1<<"道:"<<a<<"+"<<b<<"="<<endl;
if(c%4==2) cout<<"第"<<i+1<<"道:"<<a<<"-"<<b<<"="<<endl;
if(c%4==3) cout<<"第"<<i+1<<"道:"<<a<<"*"<<b<<"="<<endl;
}
return 0;
}
实验截图
标签:
原文地址:http://www.cnblogs.com/weaponx/p/4317934.html