풀이
줄 바꿈 시점에 유의하며 이중 for문으로 답을 출력합니다.
코드
C
#include <stdio.h>
int main(){
int n, i, j;
scanf("%d", &n);
for(i=0;i<n;i++){
for(j=0;j<i+1;j++){
printf("*");
}
printf("\n");
}
}
C++
# include <iostream>
using namespace std;
int main() {
int n;
cin>>n;
for (int i=0; i<n; i++){
for (int j=0;j<i+1;j++){
cout<<"*";
}
cout<<"\n";
}
}
Java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
for (int i=0;i<n;i++){
for (int j=0; j<i+1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
Python
n = int(input())
for i in range(n) :
for j in range(i+1) :
print("*", end = "")
print()