c_cpp pointers_array_example.c

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp pointers_array_example.c相关的知识,希望对你有一定的参考价值。

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;
    }
}

以上是关于c_cpp pointers_array_example.c的主要内容,如果未能解决你的问题,请参考以下文章

c_cpp 127.单词阶梯

c_cpp MOFSET

c_cpp MOFSET

c_cpp 31.下一个排列

c_cpp string→char *

c_cpp 54.螺旋矩阵