巴斯卡三角形

  • 1223
  • 0

巴斯卡三角形

舊筆記

 


#include <stdlib.h>
#include <stdio.h>

int main()
{
      int i,j,a[6][6]={101};
      char b=' ';
      for(i=0;i<=5;i++){
         printf("%*c",(6-i)*2,b);
         for(j=0;j<=i;j++){
            if(a[i-1][j]>100 || a[i-1][j-1]>100){
              a[j]=1;
              printf("%2d",a[j]);
              printf("%*c",2,b);
            }
            else{
                a[j]=a[i-1][j]+a[i-1][j-1];
                printf("%2d",a[j]);
                printf("%*c",2,b);
            }
         }
         printf("\n");
      }

      system("PAUSE");
      return 0;
}