7-5 Output Triangular Character Array (15 points)
This question requires writing a program to output n rows of triangular character arrays starting with a capital letter A.
Input format:
Input a positive integer n (1≤n<7) in one line.
Output format:
output n rows of triangle character array starting with capital letter A. See the output sample for the format, where there is a space after each letter.
Input sample:
4
Sample output:
A B C D
E F G
H I
J
在这里插入代码片
#include<stdio.h>
#include<math.h>//在此可有可无。
int main()
{
char c='A';//定义字符,从A开始。
int n;//输入的行数,每行的字符数
scanf("%d",&n);
while(n)//括号内n 表示n!=0.
{
int i;
for(i = 0; i < n; i++)
{ putchar(c++);//字符变化,eg:A→B
printf(" ");//每个字符后面都有一个空格。
}
n--;
printf("\n");//输入一行之后,换行。
}
return 0;
}