Jakorithm
article thumbnail
728x90

문제

https://www.acmicpc.net/problem/8393

 

8393번: 합

n이 주어졌을 때, 1부터 n까지 합을 구하는 프로그램을 작성하시오.

www.acmicpc.net

 

 

코드

정수 n을 입력받아 1부터 n까지의 합을 출력하는 문제다.

fun main() {
    val n = readln().toInt()
    val result = (1..n).sum()
    
    println(result)
}
728x90