在c中编写杨辉三角,输出十行

来源:百度知道 编辑:UC知道 时间:2024/05/08 10:43:52
谢谢,考试用

/******************************************************************************
打印杨辉三角:
1
1 1
1 2 1
1 3 3 1

******************************************************************************/

#define N 6 //定义三角最大行,可自行设定,但最大不要超过65536;

#include <stdio.h>

main(){

int n,i,j;
int a[N+1][2*N+4];

printf("How Many Rows Do You Want:(Number Must Below Or Equal %d)\n",N);
scanf("%d",&n);
if(n>N){
printf("What You Input Is Big Than What We Provide!\n");
exit(1);
}

//初始化数组;
for(i=1;i<=n;i++){
for(j=-1;j<2*n+2;j++){
a[i][j]=0;
}
}

a[1][n]=1;

//设置杨辉三角的数值;
for(i=1;i<=n;i++){
for