编写一个 C 语言程序,使用 for 循环打印右向帕斯卡镜像数字图案。
#include <stdio.h>
int main()
{
int rows, i, j, k;
printf("Enter Right Pascals Triangle Mirrored Numbers Rows = ");
scanf("%d", &rows);
printf("The Right Pascals Triangle of Mirrored Numbers Pattern\n");
for (i = rows; i >= 1; i--)
{
for (j = i; j <= rows; j++)
{
printf("%d ", j);
}
for (k = rows - 1; k >= i; k--)
{
printf("%d ", k);
}
printf("\n");
}
for (i = 2; i <= rows; i++)
{
for (j = i; j <= rows; j++)
{
printf("%d ", j);
}
for (k = rows - 1; k >= i; k--)
{
printf("%d ", k);
}
printf("\n");
}
}

此 C 语言程序使用 while 循环打印右向帕斯卡镜像数字图案。
#include <stdio.h>
int main()
{
int rows, i, j, k;
printf("Enter Right Pascals Triangle Mirrored Numbers Rows = ");
scanf("%d", &rows);
printf("The Right Pascals Triangle of Mirrored Numbers Pattern\n");
i = rows;
while (i >= 1)
{
j = i;
while (j <= rows)
{
printf("%d ", j);
j++;
}
k = rows - 1;
while (k >= i)
{
printf("%d ", k);
k--;
}
printf("\n");
i--;
}
i = 2;
while (i <= rows)
{
j = i;
while (j <= rows)
{
printf("%d ", j);
j++;
}
k = rows - 1;
while (k >= i)
{
printf("%d ", k);
k--;
}
printf("\n");
i++;
}
}
Enter Right Pascals Triangle Mirrored Numbers Rows = 10
The Right Pascals Triangle of Mirrored Numbers Pattern
10
9 10 9
8 9 10 9 8
7 8 9 10 9 8 7
6 7 8 9 10 9 8 7 6
5 6 7 8 9 10 9 8 7 6 5
4 5 6 7 8 9 10 9 8 7 6 5 4
3 4 5 6 7 8 9 10 9 8 7 6 5 4 3
2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2
3 4 5 6 7 8 9 10 9 8 7 6 5 4 3
4 5 6 7 8 9 10 9 8 7 6 5 4
5 6 7 8 9 10 9 8 7 6 5
6 7 8 9 10 9 8 7 6
7 8 9 10 9 8 7
8 9 10 9 8
9 10 9
10
在此 C 语言示例中,我们使用 forloopIter 函数来显示右向帕斯卡镜像数字三角形图案。
#include <stdio.h>
void rightpascalMirrored(int rows, int i)
{
for (int j = i; j <= rows; j++)
{
printf("%d ", j);
}
for (int k = rows - 1; k >= i; k--)
{
printf("%d ", k);
}
}
int main()
{
int rows, i;
printf("Enter Right Pascals Triangle Mirrored Numbers Rows = ");
scanf("%d", &rows);
printf("The Right Pascals Triangle of Mirrored Numbers Pattern\n");
for (i = rows; i >= 1; i--)
{
rightpascalMirrored(rows, i);
printf("\n");
}
for (i = 2; i <= rows; i++)
{
rightpascalMirrored(rows, i);
printf("\n");
}
}
Enter Right Pascals Triangle Mirrored Numbers Rows = 12
The Right Pascals Triangle of Mirrored Numbers Pattern
12
11 12 11
10 11 12 11 10
9 10 11 12 11 10 9
8 9 10 11 12 11 10 9 8
7 8 9 10 11 12 11 10 9 8 7
6 7 8 9 10 11 12 11 10 9 8 7 6
5 6 7 8 9 10 11 12 11 10 9 8 7 6 5
4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4
3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3
2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2
1 2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2 1
2 3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3 2
3 4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4 3
4 5 6 7 8 9 10 11 12 11 10 9 8 7 6 5 4
5 6 7 8 9 10 11 12 11 10 9 8 7 6 5
6 7 8 9 10 11 12 11 10 9 8 7 6
7 8 9 10 11 12 11 10 9 8 7
8 9 10 11 12 11 10 9 8
9 10 11 12 11 10 9
10 11 12 11 10
11 12 11
12