程序思想:
1.定义数组储存随机数,
2.while 循环30次
3.第一个判断奇偶,奇数则为整数运算,偶数为假分数运算,
4.然后为运算项,然后将随机数除以四,分别为加减乘除。
5.进行判断是否重复,不重复则储存并输出。
代码:
#include<iostream>
using namespace std;
#include<time.h>
void main()
{
int num[400];
srand(time(NULL));
for(int i=0;i<400;i++)
{
num[i]=(rand()%(99-1+1))+1;
}
int j=0,sh=0,a,b1,c,a1,a2,c1,c2,sa[30],sc[30],sa1[30],sa2[30],sc1[30],sc2[30];//a,c为a整?数簓运?算?项?,?a1a2,c1c2,假ù分?数簓运?算?项?
char b,sb[30];//b为a运?算?符?
bool s;
while(sh<30)
{
if(num[j]%2==0)//如?果?随?机ú数簓为a偶?数簓,?则ò为a整?数簓运?算?;?
{
j++;
a=num[j]; j++;
b1=num[j];j++;
if(b1%4==0){b='+';}
else if(b1%4==1){b='-';}
else if(b1%4==2){b='*';}
else if(b1%4==3){b='/';}
else continue ;
c=num[j];j++;
for(int i=0;i<sh;i++)//判D断?是?否?重?复′
{
if(sa[i]==a)
if(sb[i]==b)
if(sc[i]==c)
s=false;
}
if(s==false)
{
s=true;
continue;
}
else
{
sa[sh]=a;
sb[sh]=b;
sc[sh]=c;
sh++;
cout<<sh<<" ";
cout<<a<<b<<c<<"="<<endl;
}
}
else
{
j++;
a1=num[j]; j++;
a2=num[j]; j++;
if(a1<a2)
{
int t;
t=a1;
a1=a2;
a2=t;
}
b1=num[j];j++;
if(b1%4==0){b='+';}
else if(b1%4==1){b='-';}
else if(b1%4==2){b='*';}
else if(b1%4==3){b='/';}
else continue ;
c1=num[j];j++;
c2=num[j];j++;
if(c1<c2)
{
int t;
t=c1;
c1=c2;
c2=t;
}
for(int i=0;i<sh;i++)//判D断?是?否?重?复′
{
if(sa1[i]==a1||sa2[i]==a2||sb[i]==b||sc1[i]==c1||sc2[i]==c2)
s=false;
}
if(s==false)
{s=true;continue;}
else
{
sa1[sh]=a1;
sa2[sh]=a2;
sb[sh]=b;
sc1[sh]=c1;
sc2[sh]=c2;
sh++;
cout<<sh<<" ";
cout<<"("<<a1<<"/"<<a2<<")"<<b<<"("<<c1<<"/"<<c2<<")"<<"="<<endl;
}
}
}
}
运行图: