当前位置: 代码迷 >> C语言 >> [求助]
  详细解决方案

[求助]

热度:232   发布时间:2005-10-01 10:09:00.0
[求助]

#include "stdio.h" #include "stdlib.h" int times=0; int Total_Num; void OutTeam(Buffer,Num) int *Buffer; int Num; {int i; for (i=0;i<Num;i++) printf("%3d",Buffer[i]); printf("\n"); times++; } void MovePosition(Position,DesNum,Buffer) int Position,DesNum; int *Buffer; {Buffer[Position]=DesNum; OutTeam(Buffer,Position+1); } void SubAssign(Buffer,Position,Orig_Value,DesValue,Standard) int *Buffer; int Position,Orig_Value,DesValue,Standard; { if ((Position==Standard-1)&&(Orig_Value<=DesValue)) {MovePosition(Position,Orig_Value,Buffer); SubAssign(Buffer,Position,++Orig_Value,DesValue,Standard); } else { while(Orig_Value<=DesValue) {Buffer[Position]=Orig_Value; SubAssign(Buffer,Position+1,Buffer[Position]+1,Total_Num-(Standard-1-(Position+1)),Standard); Orig_Value++; } } }

void main(void) {int Standard; int *Buffer; int i,OrigPosition=0; fprintf(stderr,"\nHow many numbers do you want to assign\nTotal_Num="); scanf("%d",&Total_Num); fprintf(stderr,"\nWhich numbers do you want to assign in a team\nStandard="); scanf("%d",&Standard); printf("\n"); Buffer=calloc(Standard,sizeof(int)); for (i=0;i<Standard;i++) Buffer[i]=i+1; SubAssign(Buffer,OrigPosition,Buffer[OrigPosition],Total_Num-(Standard-1-OrigPosition),Standard); free(Buffer); fprintf(stderr,"\ttimes=%d",times);

} 这个程序是从1到Total_Num中选出Standard个数的全部组合,能不能把输出的数存在数组里?怎么存?请指点迷津.


----------------解决方案--------------------------------------------------------
  相关解决方案