游客 Signup | Login
中文 | En

2044 - 星号三角形

打印用*号表示的等腰三角形,接收输入一个整数指明三角形高度

Input

输入一个整数nn <= 30),以EOF结束输入

Output

输出高度为n的三角形,每打印完一个三角形都要换行,参见样例输出

Examples

Input

1
3
2

Output

*
  *
 ***
*****
 *
***

Hint

注意空格的数量,按样例为准

Solution C

#include<stdio.h>
main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++)
		{
		for(int j=1;j<=n+i;j++)
		{
			if(j<n-i)
			printf(" ");
			else
			printf("*");
		}
		printf("\n");
		}
	}
}

Solution C++

#include <iostream> 
  
int main() 
{ 
    using namespace std; 
    char star = '*'; 
    int height, weight; 
  
    while (cin >> height){ 
        weight = (2 * height - 1) / 2; 
        for (int i = 1; i <= height; i++){ 
            for (int j = 1; j <= weight; j++) 
                cout << " "; 
            for (int j = 1; j <= 2*i-1; j++) 
                cout << star; 
            cout << endl; 
            weight--; 
        } 
    } 
  
} 

Hint

注意空格的数量,按样例为准

Time Limit 1 second
Memory Limit 128 MB
Discuss Stats
上一题 下一题