打印正方形的右增量字母图案的C语言程序

52 阅读1分钟

编写一个C语言程序,使用for循环打印右增量字母图案的正方形。

#include <stdio.h

int main() { int rows;

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

printf("Rectangle of Right Incremented Alphabets Pattern\\n");
int alphabet = 65;

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

这个C语言程序使用while循环打印右侧增量字母的正方形图案。

#include <stdio.h>.

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

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

printf("Square of Right Incremented Alphabets Pattern\\n");
alphabet = 65;
i = 0;

while (i <= rows - 1)
{
	j = rows - 1;
	while (j > i)
	{
		printf("A ");
		j--;
	}

	k = 0;
	while (k <= i)
	{
		printf("%c ", alphabet + i);
		k++;
	}
	printf("\\n");
	i++;
}
Enter Square of Incremented Alphabets Rows = 16
Square of Right Incremented Alphabets Pattern
A A A A A A A A A A A A A A A A 
A A A A A A A A A A A A A A B B 
A A A A A A A A A A A A A C C C 
A A A A A A A A A A A A D D D D 
A A A A A A A A A A A E E E E E 
A A A A A A A A A A F F F F F F 
A A A A A A A A A G G G G G G G 
A A A A A A A A H H H H H H H H 
A A A A A A A I I I I I I I I I 
A A A A A A J J J J J J J J J J 
A A A A A K K K K K K K K K K K 
A A A A L L L L L L L L L L L L 
A A A M M M M M M M M M M M M M 
A A N N N N N N N N N N N N N N 
A O O O O O O O O O O O O O O O 
P P P P P P P P P P P P P P P P