Sumandos de un número

By wegols

/**
*
* @author ISRAEL CUEVA
*
*/

#include <stdio.h>

int a[50];
int x, s1, y, aux, s2,n;

main() {
printf(“Ingrese el numero: “);
scanf(“%d”, &n);
a[0] = n;
for(x=1; x<n; x++)
a[x] = 0;

while(a[0] > 1) {
x = n-1;
s1 = 0;
do { x–;
s1 = s1 + a[x];
} while(a[x] <= 1);
a[x] = a[x]-1;
aux = a[x];
s2 = a[x];
y = x + 1;

while(y < n)
if((s2 + aux) > s1)
aux = aux – 1;
else { a[y] = aux;
s2 = s2 + aux;
y++; }
for(x=0; x<n; x++)
if (a[x] != 0)
printf(“%d, “, a[x]);
printf(“\n”);
}
system(“PAUSE”);
}

Etiquetas: , , , ,

Escribe un comentario