输出内容不对
不知为什么,输出内容缺少数组中的 1,请指教(可在原程序上改编)#include "stdio.h"
void oneprintCombination(int*arr1,const int length,int start,int getcount,int*tempArr,const int tempLength,int*total1)
{
if(getcount==0)
{
(*total1)++;
for(int index=0;index<tempLength;index++)
{
printf("%d",tempArr[index]);
}
printf("\n");
return;
}
if(getcount>(length-start)||tempLength<getcount||getcount<1)
{
return;
}
for(int i=start;i<length;i++)
{
tempArr[tempLength-getcount]=arr1[i];
oneprintCombination(arr1,length,i+1,getcount-1,tempArr,tempLength,total1);
}
}
int main(int argc,char argv[])
{
int a = 0;
int*total1=&a;
int arr1[]={1,2,3,4,5,6,7,8,9,10,11,12};
int temp1[]={0,0,0,0};
oneprintCombination(arr1,12,0,5,temp1,5,total1);
printf("\n");
printf("total1:%d\n",(int)*total1);
}
输出结果:
2581011
2581012
2581112
2591011
2591012
2591112
25101112
26789
267810
267811
267812
267910
267911
267912
2671011
2671012
2671112
268910
268911
268912
2681011
2681012
2681112
2691011
2691012
2691112
26101112
278910
278911
278912
2781011
2781012
2781112
2791011
2791012
2791112
27101112
2891011
2891012
2891112
28101112
29101112
34567
34568
34569
345610
345611
345612
34578
34579
345710
345711
345712
34589
345810
345811
345812
345910
345911
345912
3451011
3451012
3451112
34678
34679
346710
346711
346712
34689
346810
346811
346812
346910
346911
346912
3461011
3461012
3461112
34789
347810
347811
347812
347910
347911
347912
3471011
3471012
3471112
348910
348911
348912
3481011
3481012
3481112
3491011
3491012
3491112
34101112
35678
35679
356710
356711
356712
35689
356810
356811
356812
356910
356911
356912
3561011
3561012
3561112
35789
357810
357811
357812
357910
357911
357912
3571011
3571012
3571112
358910
358911
358912
3581011
3581012
3581112
3591011
3591012
3591112
35101112
36789
367810
367811
367812
367910
367911
367912
3671011
3671012
3671112
368910
368911
368912
3681011
3681012
3681112
3691011
3691012
3691112
36101112
378910
378911
378912
3781011
3781012
3781112
3791011
3791012
3791112
37101112
3891011
3891012
3891112
38101112
39101112
45678
45679
456710
456711
456712
45689
456810
456811
456812
456910
456911
456912
4561011
4561012
4561112
45789
457810
457811
457812
457910
457911
457912
4571011
4571012
4571112
458910
458911
458912
4581011
4581012
4581112
4591011
4591012
4591112
45101112
46789
467810
467811
467812
467910
467911
467912
4671011
4671012
4671112
468910
468911
468912
4681011
4681012
4681112
4691011
4691012
4691112
46101112
478910
478911
478912
4781011
4781012
4781112
4791011
4791012
4791112
47101112
4891011
4891012
4891112
48101112
49101112
56789
567810
567811
567812
567910
567911
567912
5671011
5671012
5671112
568910
568911
568912
5681011
5681012
5681112
5691011
5691012
5691112
56101112
578910
578911
578912
5781011
5781012
5781112
5791011
5791012
5791112
57101112
5891011
5891012
5891112
58101112
59101112
678910
678911
678912
6781011
6781012
6781112
6791011
6791012
6791112
67101112
6891011
6891012
6891112
68101112
69101112
7891011
7891012
7891112
78101112
79101112
89101112
total1:792
Press any key to continue