[Asm] 纯文本查看 复制代码 //16. 找规律,编程序打印6×6的矩阵:
//
//1 2 3 5 8 13
//1 4 9 17 30 51
//1 6 19 45 92 173
#include<stdio.h>
#include<stdlib.h>
void main66() {
int a[6][6] = { 0 };
a[0][0] = 1;
a[0][1] = 2;
for (int j = 2; j < 6; j++) {
a[0][j] = a[0][j - 1] + a[0][j - 2];
}
for (int i = 1; i < 6; i++) {
for (int j = 0; j < 6; j++) {
if (j == 0) {
a[i][j] = 1;
}
else {
a[i][j] = a[i][j - 1] + a[i - 1][j] + a[i - 1][j - 1];
}
}
}
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 6; j++) {
printf("%5d", a[i][j]);
}
printf("\n");
}
getchar();
}
/*
21. 请编程序按如下格式打印一个直角三角形的九九乘法表:
1 2 3 4 5 6 7 8 9
4 6 8 10 12 14 16 18
9 12 15 18 21 24 27
16 20 24 28 32 36
25 30 35 40 45
36 42 48 54
49 56 63
64 72
81
*/
void main() {
int a[9][9] = { 0 };
for (int i = 0; i < 9; i++) {
for (int j = i; j < 9; j++) {
a[i][j] = (i + 1)*(j + 1);
}
}
for (int i = 0; i < 9; i++) {
printf("%*d", 4 * i+1, a[i][i]);
for (int j = i + 1; j < 9; j++) {
printf("%4d", a[i][j] = (i + 1)*(j + 1));
}
printf("\n");
}
getchar();
} |