void TestArray(int d[],int n, int total)
{
int i , j;
double sum;
int count = 0;
for (i = 0;i<(1<<n);i++)
{
sum= 0.0;
for(j=0; j<n; j++)
{
if(i&(1<<j))
sum+= d[j];
}
if (total== sum)
{
printf("%d:",++count);
for (j= 0 ; j<n; j++)
{
if(i&(1<<j))
printf("%d+",d[j]);
printf("\b\b=%d.\n,total");
}
}
printf("\ntotal case :%d.\n",count);
getch();
return;
}
}
void main()
{
int d[7]= {1,2,3,4,5,10};
TestArray(d[7],2,15);
printf("close");
system("pause");
void poker(int * const a_iPoker, const int a_iCount)
{
int *AssignAlready = new int[a_iCount];
// Assume none of the cards assigned.
memset(AssignAlready,0,sizeof(int) * a_iCount);
int i;
int iIndex;
//Seed the random-number generator with current time so that
//the numbers will be different every time we run.
srand( (unsigned)time(NULL));
for(i = 0; i < a_iCount; i ++)
{
// get the random index
double dRand = (double)rand() * (a_iCount - 1)/ RAND_MAX;
iIndex = (int)dRand;