728x90
바로가기 : JAVA 풀이 C언어 풀이 Python 풀이
링크 : https://www.acmicpc.net/problem/2741
문제
자연수 N이 주어졌을 때, 1부터 N까지 한 줄에 하나씩 출력하는 프로그램을 작성하시오.
입력
첫째 줄에 100,000보다 작거나 같은 자연수 N이 주어진다.
출력
첫째 줄부터 N번째 줄 까지 차례대로 출력한다.
예제 입력 1
5
예제 출력 1
1
2
3
4
5
JAVA 풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for (int i = 1; i <= n; i++) {
System.out.println(i);
}
}
}
C언어 풀이
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
printf("%d\n", i);
}
return 0;
}
Python 풀이
n = int(input())
for i in range(1, n + 1):
print(i)
728x90