【求助!】C语言程序设计课速算24的程序,显示的结果好多重复的,怎么改?
#include<stdio.h> double fun(double a1,double a2,int b)
{switch(b)
{case 0:return (a1+a2);
case 1:return (a1-a2);
case 2:return (a1*a2);
case 3:return (a1/a2);
}
}
void main()
{int q,i,j,k,l,n,m,r,save[4],count=0;
double num[4]={1,1,1,1},tem1,tem2,tem3,abc=1111;
char sign[5]="+-*/";
printf(" 欢迎使用计算“24”程序\n");
printf("请输入4个数字:\n");
for(i=0;i<4;i++)
{scanf("%lf",num+i); save[i]=num[i];}
printf("请输入希望计算的值如(24)");
scanf("%d",&q);
for(i=0;i<4;i++)
for(j=0;j<4;j++)
if(j!=i)
{for(k=0;k<4;k++)
if(k!=i&&k!=j)
{for(l=0;l<4;l++)
if(l!=i&&l!=j&&l!=k)
{for(n=0;n<4;n++)
for(m=0;m<4;m++)
for(r=0;r<4;r++)
{tem1=fun(num[i],num[j],n);
tem2=fun(tem1,num[k],m);
tem3=fun(tem2,num[l],r);
if(tem3==q){printf("{(%d%c%d)%c%d}%c%d=%d\n\n",save[i],sign[n],save[j],sign[m],save[k],sign[r],save[l],q);count=count+1;}
else if(tem3==-1*q){printf("{%d%c(%d%c%d)}%c%d=%d\n\n",save[k],sign[m],save[i],sign[n],save[j],sign[r],save[l],q); count=count+1;}
else if(tem3==1.0/q){printf("%d%c{(%d%c%d)%c%d}=%d\n\n",save[l],sign[r],save[i],sign[n],save[j],sign[m],save[k],q); count=count+1;}
else if(tem3==-1.0/q){printf("%d%c{%d%c(%d%c%d)}=%d\n\n",save[l],sign[r],save[k],sign[n],save[i],sign[m],save[j],q);count=count+1;}
else
{tem1=fun(num[i],num[j],n);
tem2=fun(num[k],num[l],r);
tem3=fun(tem1,tem2,m);
if(tem3==q) {printf("(%d%c%d)%c(%d%c%d)=%d\n\n",save[i],sign[n],save[j],sign[m],save[k],sign[r],save[l],q); count=count+1;}
}
}
}
}
}
if(count==0)printf("\n\n您所输入的4个数无法通过排列运算得出您所输入的值");
getchar();
getchar();}