zoukankan      html  css  js  c++  java
  • 杨辉三角

    杨辉三角

    问题描述:使用二维数组计算并打印杨辉三角的前10行

    1

    1             1

    1        2       1

    1        3       3       1

    1        4       6       4       1

    1        5       10     10     5       1

    1        6       15     20     15     6       1

    1        7       21     35     35     21     7       1

    1        8       28     56     70     56     28     8       1

    1        9       36     84     126  126  84     36     9       1

     1 public class Main {
     2 
     3     public static void main(String[] args) {
     4         int[][] num = new int[10][];
     5         
     6         for(int i = 0; i<num.length; i++){
     7             num[i] = new int[i+1];
     8             for(int j = 0; j<num[i].length; j++){
     9                 if(i==0 || i==1 || j == 0 || j==num[i].length-1){
    10                     num[i][j] = 1;
    11                 }else{
    12                     num[i][j]=num[i-1][j-1] + num[i-1][j];
    13                 }
    14             }
    15         }
    16         
    17         for(int i = 0; i<num.length; i++){
    18             for(int j = 0; j<num[i].length; j++){
    19                 System.out.print(num[i][j]+"	");
    20             }
    21             System.out.println();
    22         }
    23     }
    24 }
    View Code
  • 相关阅读:
    类的加载过程
    ASCII码表
    uboot main_loop函数分析
    串行CPU设计
    __attribute__ ((section(".text")))的测试
    NandFlash
    测试gcc的优化选项
    如何编写一个简单的makefile
    UBOOT的多支持性与可裁剪性
    函数指针的使用
  • 原文地址:https://www.cnblogs.com/jinyufanfan/p/10112937.html
Copyright © 2011-2022 走看看