码迷,mamicode.com
首页 > 其他好文 > 详细

能自动生成小学四则运算题目

时间:2017-09-15 02:16:09      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:htm   cout   operator   time   自动生成   rand   and   ase   类型   

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

char Operator()
{
char op;
int i;
i=rand()%4+1;
switch(i)
{
case 1: return ‘+‘;
case 2: return ‘-‘;
case 3: return ‘x‘;
case 4: return ‘/‘;
}
}

void integer()
{
int x,y;
char op;
x=rand()%100+1;
y=rand()%100+1;
op=Operator();
if(op==‘-‘)
while(x<y)
{
x=rand()%100+1;
y=rand()%100+1;
}
cout<<x<<op<<y<<"="<<endl;
}

void fraction()
{
int a,b,c,d;
a=rand()%100+1;
b=rand()%100+1;
c=rand()%100+1;
d=rand()%100+1;
char op;
while(a<=b||c<=d)
{
a=rand()%100+1;
b=rand()%100+1;
c=rand()%100+1;
d=rand()%100+1;
}
op=Operator();
if(op==‘-‘)
while((b*c-a*d)<0)
{
a=rand()%100+1;
b=rand()%100+1;
c=rand()%100+1;
d=rand()%100+1;
}
cout<<b<<"/"<<a<<op<<d<<"/"<<c<<"="<<endl;
}

void main()
{
A:srand(time(0));
int i,n,m;
cout<< "请输入出题类型"<<endl;
cout<< "1.整数四则运算"<<endl;
cout<< "2.分数四则运算"<<endl;
cin>>i;
cout<< "请输入出题数目"<<endl;
cin>>n;
for(m=1;m<=n;m++)
{
if(i==1)
integer();
else
fraction();
}

goto A;

}

 

 

来源:http://www.cnblogs.com/m108280546/p/5269702.html

感谢王敬一

能自动生成小学四则运算题目

标签:htm   cout   operator   time   自动生成   rand   and   ase   类型   

原文地址:http://www.cnblogs.com/MeiT/p/7523699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!