import java.util.*; public class Main { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int a[][] = new int[n][n]; a[0][0] = 1; for(int i=1;i<=n-1;i++) { a[i][0] = a[i-1][0] + i; for(int j=1;j<=n-1;j++) { a[i][j] = a[i][j-1] + j + i + 1; } } for(int m=1;m<n;m++) { a[0][m] = a[0][m-1] + m + 1; } for(int x=0;x<n;x++) { for(int y=0;y<n-x;y++) { System.out.print(a[x][y]+" "); } System.out.println(); } } }
解题思路:
对于每一组数据,输出一个N行的蛇形矩阵。两组输出之间不要额外的空行。 矩阵三角中同一行的数字用一个空格分开。行尾不要多余的空格。 1 3 6 10 15 2 5 9 14 4 8 13 7 12 11
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:610 |
蛇行矩阵 (C语言代码)浏览:539 |
Cylinder (C语言描述,蓝桥杯)浏览:1250 |
1157题解浏览:733 |
sizeof的大作用 (C语言代码)浏览:1502 |
C二级辅导-进制转换 (C语言代码)浏览:687 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:672 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:448 |
2005年春浙江省计算机等级考试二级C 编程题(2) (C语言描述之函数调用)浏览:819 |
A+B for Input-Output Practice (V) (C语言代码)浏览:707 |