#include <stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
int multiplication(long num) //有乘除法
{
int a,b,c,p,i;
int x = num+1;
a=rand()%x;
b=rand()%x;
p=rand()%4;
if(p==0)
{
if(a<b)
{
c=a;
a=b;
b=c;
}
printf(" %d-%d=
",a,b);
}
if(p==1)
printf(" %d+%d=
",a,b);
if(p==2)
printf(" %d×%d=
",a,b);
if(p==3)
printf(" %d÷%d=
",a,b);
}
void no_multiplication(long num) //无乘除法
{
int a,b,c,p,i;
int x = num+1;
a=rand()%x;
b=rand()%x;
p=rand()%2;
if(p==1)
printf(" %d+%d=
",a,b);
if(p==0)
{
if(a<b)
{
c=a;
a=b;
b=c;
}
printf(" %d-%d=
",a,b);
}
}
int main()
{
int i; /极限/计数器
long num; //数据范围
char IsMul[5];
srand(time(0));
printf("请输入算数题目范围(即所允许的最大值)
");
scanf("%ld",&num);
printf("请输入是否加入乘除法,‘yes’ OR ‘no’
");
scanf("%s",IsMul);
printf("***********************题目为:***********************
");
if(strcmp(IsMul,"yes")==0)
{
for(i=0;i<20;i++)
multiplication(num);
}
else {
for(i=0;i<20;i++)
no_multiplication(num);
}
return 0;
}