问题链接:CCF NOI1031 等腰三角形。
时间限制:
1000 ms 空间限制: 262144 KB
题目描述
输入一个正整数n,输出高为n的由*组成的等腰三角形。
输入
输入一个正整数。
输出
输出高为n的由*组成的等腰三角形。
样例输入
3
样例输出
* *** *****数据范围限制
1<=n<=20
问题分析
打印等腰三角形,关键是循环控制。程序中需要控制好总行数和每一行的字符。
每一行的字符从左到右包括空格(可能是0个)、*号字符(若干个)和换行符。
程序说明
将打印功能封装在函数delta()中,可以使得主程序变得更加简洁。
- 循环变量与空格数,*符号数量的函数关系。
参考链接:I00006 打印等腰三角形字符图案(底边在下) 。
100分通过的C语言程序:
/* 打印等腰三角形字符图案(底边在下) */ #include <stdio.h> void delta(int n) { int i; for(i=1; i<=n; i++){ int j; for(j=1; j<=n-i; j++) printf(" "); for(j=1; j<=2*i-1; j++) printf("*"); printf(" "); } } int main(void) { int n; scanf("%d", &n); delta(n); return 0; }