Ejemplo n.º 1
0
/* Driver function to test above functions */
int main()
{
  int n = 5,c=0;
  printf("Differnt compositions formed by 1, 2 and 3 of %d are\n", n);
    scanf("%d",&n);
    int i,j;
    
     for(i=0;i<n;i++){
          scanf("%d",&arr1[i]);
         printf("%d ",arr1[i]);
     }
    max=arr1[n-1];
     for(i=n;i>0;i--)
            {
             j=n-i;
             c=0;
         c=c+arr1[i-1];
         MAX_POINT=j;
                c+= printCompositions(j, 0);
                if(max<c)
                    max=c;
         f=0;f1=0;
     }
    printf("%d",max);
  return 0;
}
int main()
{
  int n = 5;
  printf("Differnt compositions formed by 1, 2 and 3 of %d are\n", n);
  printCompositions(n, 0);
  getchar();
  return 0;
}
void printCompositions(int n, int i)
{

  static int arr[ARR_SIZE];
 
  if (n == 0)
  {
    printArray(arr, i);
  }
  else if(n > 0)
  {
    int k; 
    for (k = 1; k <= MAX_POINT; k++)
    {
      arr[i]= k;
      printCompositions(n-k, i+1);
    }
  }
}
Ejemplo n.º 4
0
int printCompositions(int n, int i)
{
  if (n == 0)
  {
    f=printArray(arr, i);
      if(f>f1)
          f1=f;
      return f1;
  }
  else if(n > 0)
  {
    int k; 
    for (k = 1; k <= MAX_POINT; k++)
    {
      arr[i]= k;
       printCompositions(n-k, i+1);
    }
  }
    return f1;
}