본문 바로가기

Algorithm

(C++)백준 알고리즘 2741 - N 찍기

출처 : https://www.acmicpc.net/problem/2741

 

2741번: N 찍기

자연수 N이 주어졌을 때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.

www.acmicpc.net

문제

자연수 N이 주어졌을때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.

 

입력

첫째 줄에 100,000보다 작거나 같은 자연수 N이 주어진다.

 

출력

첫째 줄부터 N번째 줄 까지 차례대로 출력한다.

#include<bits/stdc++.h>

using namespace std;

int main() {
	cin.tie(NULL); ios::sync_with_stdio(false);
	int N;
	scanf("%d", &N);
	//cin >> N;

	for (int i = 1; i <= N; i++) {
		printf("%d\n", i);
		//cout << i << '\n';
	}

	return 0;
}

for반복문을 이용하여 N번 반복하고 매번 출력을 해준다.

 

결과