void pascalDiagonal(int n, int k, int aDiag[]);
#define DIAGSTART 3
#define PRINTROWS 120
long binomialC(int n, int k){
if (n == 0 || k == 0) return 1;
else return binomialC(n-1, k) + binomialC(n, k-1);
}
void pascalDiagonal(int n, int k, int aDiag[]) {
int counter = 0;
for (counter = 0; counter < n; counter++){
aDiag[counter] = binomialC(counter,k);
}
}
int main(){
//Program to print a diagonal of Pascal triangle
int diagonalStart = DIAGSTART; // which diagonal you want to print
int rows = PRINTROWS; // how many rows you want to print
if (diagonalStart < 1 || rows < 1) return 0;
int n = rows + diagonalStart-1;
int k = diagonalStart-1;
int *aDiag;
aDiag = malloc(k * sizeof(int));
pascalDiagonal(n, k, aDiag);
printArray(&aDiag[0], rows);
return 0;
}
void printArray(int *pA, int mySize){
int n = 0;
for (n = 0; n < mySize; n++){
printInteger(*(pA+n));
printLineBreak;
}
}