C语言:输出杨辉三角形前n行 #include <stdio.h>#defineN 10main() {intshu[N][N]={0},a,b,c;for(a=0;a<N;a++) {for(c=N-1-a;c>=0;c=c-1) printf("") ;for(b=0;b<=a;b++) { shu[a][b]=1;if(!(a==0|| a==b)) shu[a][b]=shu[a-1][b-1]+shu[a-1][b];...
C语言:输出杨辉三角形前n行 C语⾔:输出杨辉三⾓形前n⾏#include <stdio.h> #define N 10 main(){ int shu[N][N]={0},a,b,c;for(a=0;a<N;a++){ for(c=N-1-a;c>=0;c=c-1)printf("") ;for(b=0;b<=a;b++){ shu[a][b]=1;if(!(a==0 || a==b)) shu[a][b]...
include <stdio.h>#include <stdlib.h>int main(){// 数值和高度 int s = 1, h; // 循环计数 int i, j; printf("输入行数:");// 输入层数 scanf("%d", &h); // 输出第一个 1 printf("1\n"); // 行数 i 从 2 到层高 for (i = 2; i <...
//#include "stdafx.h"//vc++6.0加上这一行.include "stdio.h"int main(void){ int i,j,a[14]={0,1,},n;printf("Input n(<14)...\nn=");scanf("%d",&n);for(*(a+1)=i=1;i<=n;i++){ printf("%*c",(n-i)*2+1,' ');for(j=i;j>=1;j--)printf("%4d",...
{ int value = 0;if ( b == 1 || b == a )//开头和结尾 { value = 1;} else value = c ( a - 1 , b - 1)+c(a-1,b);//中间的值,递归 return value;} void main(){ int n;int j = 0;printf("你要输入多少行?\n");scanf("%d",&n);while ( n > 13 ) /...
输出杨辉三角的代码如下:#includevoidmain(){inti,j;inta[10][10];printf("\n");for(i=0;i<10;i++) { a[i][0]=1; a[i][i]=1; }for(i=2;i<10;i++) for(j=1;j
include<stdio.h>int main(){int n;printf("输入行数:");while(scanf("%d",&n)!=EOF){int a[31][31];int i,j,k;for(i=1;i<=30;i++)a[i][1]=a[i][i]=1;if(n==1)printf("1\n");if(n>=2)printf("1\n1 1\n");for(i=3;i<=n;i++){printf("1 ");for(...
include<stdio.h> int main(){ int n=5,i,j,a[10]={1};for(i=0;i<=n;i++){printf("%*c",2*(n-i)+1,' ');for(j=i;j>0;j--)a[j]=a[j]+a[j-1];for(j=0;j<=i;j++)printf("%-4d",a[j]);printf("\n");} getch();} ...
} for (j=0;j<x;j++)for (i=0;i<=j;i++){ printf("%-5d",a[j][i]) ;if (i==j)printf("\n");} } void main(){ int x;do { printf("\n");scanf("%d",&x);if(x>16)break;yhsj(x);} while(x<17) ;printf("错误\n");} ...
for(i=1;i<n;i++)for(j=1;j<=i;j++)a[i][j]=a[i-1][j-1]+a[i-1][j];/*每个数是上面两数之和*/ for(i=0;i<n;i++) /*输出杨辉三角*/ { for(j=0;j<=i;j++)printf("%5d",a[i][j]);printf("\n");} } 这里有两个,都是c语言的,不过相信你可以将...