51Nod 2414 啓蒙練習-圖形輸出2 刷題筆記

1. 題目描述

1.1. Limit

Time Limit: 1000 ms

Memory Limit: 131072 kB

1.2. Problem Description

輸入一個數nn,輸出nn層圖形,見下(圖爲n=4n=4的情況)

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

1.3. Input

輸入一個數NN


1.4. Output

輸出相應的圖形


1.5. Sample Input

5

1.6. Sample Output

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

1.7. Source

2414 啓蒙練習-圖形輸出2


2. 解讀

假設行號爲 iii[0,N1]i \in [0, N-1],每一行輸出 2×i12 \times 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");
    }
}

聯繫郵箱:[email protected]

Github:https://github.com/CurrenWong

歡迎轉載/Star/Fork,有問題歡迎通過郵箱交流。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章