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

136 阅读1分钟

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

#include <stdio.h

int main() { int rows, alphabet = 65;

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

printf("Printing Downward Triangle of Alphabets Pattern\\n");
for (int i = 0; i <= rows - 1; i++)
{
	for (int j = rows - 1; j >= i; j--)
	{
		printf("%c ", alphabet + j);
	}
	printf("\\n");
}

image.png

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

#include <stdio.h>.

int main() {

int i, j, rows, alphabet = 65;

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

printf("Printing Downward Triangle of Alphabets Pattern\\n");

i = 0;
while (i <= rows - 1)
{
	j = rows - 1;
	while (j >= i)
	{
		printf("%c ", alphabet + j);
		j--;
	}
	printf("\\n");
	i++;
}
Enter Downward Triangle of Alphabets Rows = 10
Printing Downward Triangle of Alphabets Pattern
J I H G F E D C B A 
J I H G F E D C B 
J I H G F E D C 
J I H G F E D 
J I H G F E 
J I H G F 
J I H G 
J I H 
J I 
J 

这个C程序使用do while循环来显示字母的下三角图案。

#include <stdio.h>.

int main() {

int i, j, rows, alphabet = 65;

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

printf("Printing Downward Triangle Alphabets Pattern\\n");

i = 0;
do
{
	j = rows - 1;
	do
	{
		printf("%c ", alphabet + j);

	} while (--j >= i);
	printf("\\n");

} while (++i <= rows - 1);
Enter Downward Triangle of Alphabets Rows = 16
Printing Downward Triangle Alphabets Pattern
P O N M L K J I H G F E D C B A 
P O N M L K J I H G F E D C B 
P O N M L K J I H G F E D C 
P O N M L K J I H G F E D 
P O N M L K J I H G F E 
P O N M L K J I H G F 
P O N M L K J I H G 
P O N M L K J I H 
P O N M L K J I 
P O N M L K J 
P O N M L K 
P O N M L 
P O N M 
P O N 
P O 
P