游客 Signup | Login
中文 | En

3876 - 4.18(1) 使用循环语句打印图案

编写程序,提示用户输入一个在1到30之间的整数,然后显示一个正上三角形状的图案。

Input

输入一个在1到30之间的整数n


Output

显示一个n行正上三角形状的图案,每个数字之间空一格。如:


1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 

Examples

Input

6

Output

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 

Hint

大于9的数字占2位

Solution C

#include <stdio.h>

int main()
{
    int i, j, n, a, b;

    scanf("%d" ,&n);

    for(i = 1; i <= n ; i++)
    {
        for (j = 1; j <= i; j++)
        {
            printf("%d ", j);
        }
        printf("\n");
    }

    return 0;
}

Solution C++

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=i;j++)
        {
            cout<<j<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Hint

大于9的数字占2位

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