Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 931 byte
#include <stdio.h>
#define MaxN 100
int A[MaxN];
void MakePartitions (int);
void Print (int);
int main (void) {
printf("<-- Start -->\n");
MakePartitions(10);
return 0;
}
void MakePartitions (int N) {
int I, M = 1, Q = 0, D;
long P = 1;
if (N > MaxN || N < 2)
return;
A[0] = N;
while (Q >= 0) {
D = A[Q] - 1;
for (N = M - Q + D; N > D; N-= D, Q++)
A[Q] = D;
A[Q] = N;
M = Q + 1;
for (; Q >= 0 && A[Q] == 1; Q--);
P++;
}
printf("There are %ld partitions.\n", P);
}
void Print (int M) {
for (int I = 0; I < M; I++)
printf("%d ", A[I]);
printf("\n");
}