打印下三角镜面字母图案的C语言程序

131 阅读1分钟

编写一个C语言程序,使用for循环打印下三角镜面字母图案。

#include <stdio.h

int main() { int rows;

printf("Enter Downward Triangle of Mirrored Alphabets Rows = ");
scanf("%d", &rows);

printf("Printing Downward Triangle of Mirrored Alphabets Pattern\\n");
int alphabet = 65;

for (int i = 0; i <= rows - 1; i++)
{
	for (int j = i; j <= rows - 1; j++)
	{
		printf("%c ", alphabet + j);
	}
	for (int k = rows - 2; k >= i; k--)
	{
		printf("%c ", alphabet + k);
	}
	printf("\\n");
}

C Program to Print Downward Triangle Mirrored Alphabets Pattern

这个C范例使用while循环打印镜像字母的下三角模式。

#include <stdio.h>.

int main() { int i, j, k, alphabet, rows;

printf("Enter Downward Triangle of Mirrored Alphabets Rows = ");
scanf("%d", &rows);

printf("Printing Downward Triangle of Mirrored Alphabets Pattern\\n");
alphabet = 65;
i = 0;

while (i <= rows - 1)
{
	j = i;
	while (j <= rows - 1)
	{
		printf("%c ", alphabet + j);
		j++;
	}

	k = rows - 2;
	while (k >= i)
	{
		printf("%c ", alphabet + k);
		k--;
	}
	printf("\\n");
	i++;
}
Enter Downward Triangle of Mirrored Alphabets Rows = 16
Printing Downward Triangle of Mirrored Alphabets Pattern
A B C D E F G H I J K L M N O P O N M L K J I H G F E D C B A 
B C D E F G H I J K L M N O P O N M L K J I H G F E D C B 
C D E F G H I J K L M N O P O N M L K J I H G F E D C 
D E F G H I J K L M N O P O N M L K J I H G F E D 
E F G H I J K L M N O P O N M L K J I H G F E 
F G H I J K L M N O P O N M L K J I H G F 
G H I J K L M N O P O N M L K J I H G 
H I J K L M N O P O N M L K J I H 
I J K L M N O P O N M L K J I 
J K L M N O P O N M L K J 
K L M N O P O N M L K 
L M N O P O N M L 
M N O P O N M 
N O P O N 
O P O 
P