51Nod 2414 启蒙练习-图形输出2 刷题笔记
文章目录
1. 题目描述
1.1. Limit
Time Limit: 1000 ms
Memory Limit: 131072 kB
1.2. Problem Description
输入一个数 n,输出 n层图形,见下(图为 n=4的情况)
*
***
*****
*******
1.3. Input
输入一个数 N
1.4. Output
输出相应的图形
1.5. Sample Input
5
1.6. Sample Output
*
***
*****
*******
*********
1.7. Source
2. 解读
假设行号为 i, i∈[0,N−1],每一行输出 2×i−1 个符号 ∗。
3. 代码
#include <iostream>
using namespace std;
int main()
{
    long long n;
    // 读入n
    scanf("%lld", &n);
    // 输出图形
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2 * i + 1; j++) {
            printf("*");
        }
        printf("\n");
    }
}
联系邮箱:curren_wong@163.com
Github:https://github.com/CurrenWong
欢迎转载/Star/Fork,有问题欢迎通过邮箱交流。
 查看30道真题和解析
查看30道真题和解析
