请编写函数,用循环方法显示等腰三角形(向上)。
函数原型
void UpIso(int height, char symbol);
说明:参数 height 为等腰三角形的高,symbol 为显示字符。函数将在屏幕下显示高度为 height 底宽为 2 * height - 1 由字符 symbol 组成的等腰三角形(向上)。若 height ≤ 0,则不输出。
裁判程序
#include <stdio.h>
void Show(int number, char symbol);
void UpIso(int height, char symbol);
int main()
{
int n;
char s;
scanf("%d %c", &n, &s);
UpIso(n, s);
putchar('\n');
return 0;
}
......
/* 你提交的代码将被嵌在这里 */
提示:需要利用前面作业中的 Show 函数。
输入样例1
-3 #
输出样例1
输入样例2
5 *
输出样例2
*
***
*****
*******
*********
要求:不使用选择语句。
关联习题:重复显示字符(循环版)。
void UpIso(int height, char symbol)
{
int s = height;
for(int i=1;i<=height;i++)
{
Show(s-1,' ');//空格递减
Show(2*i-1,symbol);//*2*i-1递增
putchar('\n');//注意每次换行
s--;
}
}