[백준 2439] 별 찍기 - 2 (C#, C++) - soo:bak
작성일 :
문제 링크
설명
1 번째 줄부터 n 번째 줄까지, 각 줄에 공백 문자와 * 문자를 출력하는 문제입니다. 
각 줄에 출력해야하는 * 의 개수는 줄의 행 번호와 일치합니다. 
다만, * 문자가 우측으로 정렬되도록, 즉, 공백 문자를 n - 행번호 만큼 먼저 출력하여야 합니다. 
Code
[ C# ] 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace Solution {
  class Program {
    static void Main(string[] args) {
      var n = int.Parse(Console.ReadLine()!);
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
          if (j <= (n - i)) Console.Write(" ");
          else Console.Write("*");
        }
        Console.WriteLine();
      }
    }
  }
}
[ C++ ] 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (j <= (n - i)) cout << " ";
      else cout << "*";
    }
    cout << "\n";
  }
  return 0;
}