回复 18楼 吹水佬
显示组合情况,应该没重复了吧:
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
#include <stdio.h>
#include <stdlib.h>
main()
{
int i, j, k, z, m, n, count=0;
printf("分别输入8角和5角的张数:");
scanf("%d%d",&m,&n);
k = 8*m+5*n+1;
char *c = (char*)calloc(k, sizeof(char));
int *ci = (int*)calloc(k, sizeof(int));
int *cj = (int*)calloc(k, sizeof(int));
for (i=0; i<=m; i++)
{
for(j=0; j<=n; j++)
{
z = i*8+j*5;
c[z] = 1;
ci[z] = i;
cj[z] = j;
//c[z]++;
}
}
for (i=1; i<k; i++) //c[0]的不算
{
if (c[i])
{
count++;
printf("组合%d\t%d张8角+%d张5角\t%d角\n", count, ci[i], cj[i], i);
}
}
printf("共有%d种组合\n",count);
free(c);
free(ci);
free(cj);
}