使用 for 循环编写 C 程序,在右三角的每列打印相同的字母。或者,编写一个程序,使用 for 循环在右三角的每列打印重复的字符或相同的字母。
#include <stdio.h>
int main()
{
int i, j, rows, alphabet = 65;
printf("Enter Right Triangle Columns with Same Alphabets Rows = ");
scanf("%d",&rows);
printf("Right Triangle Columns with Same Alphabets Pattern\n");
for (i = 0 ; i < rows; i++ )
{
for (j = 0 ; j <= i; j++ )
{
printf("%c ", alphabet);
}
alphabet++;
printf("\n");
}
return 0;
}

此 C 示例使用 while 循环显示右三角模式,其中每列重复相同的字符。
#include <stdio.h>
int main()
{
int i = 0, j, rows, alphabet = 65;
printf("Enter Right Triangle Columns with Same Alphabets Rows = ");
scanf("%d",&rows);
printf("\nRight Triangle Columns with Same Alphabets Pattern\n");
while ( i < rows )
{
j = 0 ;
while( j <= i)
{
printf("%c ", alphabet);
j++ ;
}
alphabet++;
printf("\n");
i++;
}
return 0;
}
Enter Right Triangle Columns with Same Alphabets Rows = 12
Right Triangle Columns with Same Alphabets Pattern
A
B B
C C C
D D D D
E E E E E
F F F F F F
G G G G G G G
H H H H H H H H
I I I I I I I I I
J J J J J J J J J J
K K K K K K K K K K K
L L L L L L L L L L L L
使用 do while 循环打印相同字母在每个右三角行-列的 C 程序。
#include <stdio.h>
int main()
{
int i = 0, j, rows, alphabet = 65;
printf("Enter Right Triangle Columns with Same Alphabets Rows = ");
scanf("%d",&rows);
printf("\nRight Triangle Columns with Same Alphabets Pattern\n");
do
{
j = 0 ;
do
{
printf("%c ", alphabet);
} while( ++j <= i);
alphabet++;
printf("\n");
} while ( ++i < rows );
return 0;
}
Enter Right Triangle Columns with Same Alphabets Rows = 15
Right Triangle Columns with Same Alphabets Pattern
A
B B
C C C
D D D D
E E E E E
F F F F F F
G G G G G G G
H H H H H H H H
I I I I I I I I I
J J J J J J J J J J
K K K K K K K K K K K
L L L L L L L L L L L L
M M M M M M M M M M M M M
N N N N N N N N N N N N N N
O O O O O O O O O O O O O O O