本文目录一览:
c语言彩票兑奖程序
#includestdio.h
void main()
{
int a[]={1,2,3,4,5,6,7};
int b[7],i,j,count=0,max=0,maxflag;
for(i=0;i7;i++)
scanf("%d",b[i]);
i=0;
while(i7)
{
j=0;
count=0;
if(b[i]==a[j])
while(i7 j7 b[i]==a[j]) i++,j++,count++;
else
i++;
if(maxcount) {max =count;maxflag=i;}
}
count = max;
if(count==7) printf("特等奖\n");
else if(count==6)
{
if(maxflag==7)
printf("二等奖\n");
else
printf("一等奖\n");
}
else if(count==5)
{
if(maxflag==7)
printf("三等奖\n");
else
printf("二等奖\n");
}
else if(count==4)
{
if(maxflag==7)
printf("四等奖\n");
else
printf("三等奖\n");
}
else if(count==3)
{
if(maxflag==7)
printf("五等奖\n");
else
printf("四等奖\n");
}
else if(count==2 maxflag!=7)
printf("五等奖\n");
else
printf("没中奖\n");
}
如何用C语言编一个彩票32选8并显示所有排列组合的程序。
void f()
{
int i1,i2,i3,i4,i5,i6,i7,i8;
for (i1=1;i132;i1++)
for (i2=1;i232;i2++){if (i1==i2) continue;
for (i3=1;i332;i3++){if (i1==i3) continue; if (i2==i3) continue;
for (i4=1;i432;i4++){if (i1==i4) continue; if (i2==i4) continue; if (i3==i4) continue;
for (i5=1;i532;i5++){if (i1==i5) continue; if (i2==i5) continue; if (i3==i5) continue; if (i4==i5) continue;
for (i6=1;i632;i6++){if (i1==i6) continue; if (i2==i6) continue; if (i3==i6) continue; if (i4==i6) continue; if (i5==i6) continue;
for (i7=1;i732;i7++){if (i1==i7) continue; if (i2==i7) continue; if (i3==i7) continue; if (i4==i7) continue; if (i5==i7) continue; if (i6==i7) continue;
for (i8=1;i832;i8++){if (i1==i8) continue; if (i2==i8) continue; if (i3==i8) continue; if (i4==i8) continue; if (i5==i8) continue; if (i6==i8) continue; if (i7==i8) continue;
printf("%d,%d,%d,%d,%d,%d,%d,%d\n",i1,i2,i3,i4,i5,i6,i7,i8);
}}}}}}}
}
不过估计没有什么用,因为输出的组合数多达
31*30*29*28*27*26*25/(1*2*3*4*5*6*7*8)个
没有实际意义。
求用C语言编写彩票6+1程序
#include stdio.h
main()
{
int p[7],q[7],n,i; /****p:投注号码,q:开奖号码****/
char c='0';
st(p,q); /****初始化****/
n=pd(p,q);
switch (n)
{
case 6:
{
if(p[6]==q[6]) c='!';
else c='1';
} break;
case 5:
{
if(p[1]!=q[1]||p[4]!=q[4]) c='3';
if(p[2]!=q[2]||p[3]!=q[3]) c='0';
else c='2';
} break;
case 4:
{
if((p[0]!=q[0]p[1]!=q[1])||(p[0]!=q[0]p[5]!=q[5])||(p[4]!=q[4]p[5]!=q[5]))
c='3';
else c='0';
}
}
switch (c )
{
case '!': printf("\nni zhong le te deng jiang!");break;
case '1': printf("\nni zhong le 1 deng jiang!"); break;
case '2': printf("\nni zhong le 2 deng jiang!"); break;
case '3': printf("\nni zhong le 3 deng jiang!"); break;
case '0': printf("\nni mei you zhong jiang!"); break;
}
getch();
}
st(int p[],int q[])
{
int i;
printf("\nXuan zhe tou zhu hao ma: ");
for(i=0;i7;i++)
scanf("%d",p[i]);
printf("\nKai jiang hao ma shi: ");
for(i=0;i7;i++)
scanf("%d",q[i]);
}
pd(int p[],int q[])
{
int i,n=0;
for(i=0;i6;i++)
if(p[i]==q[i])
n++;
return(n);
}