준코딩

[Swift] 백준 8393번 문제 합 본문

알고리즘/Swift 백준 문제풀이

[Swift] 백준 8393번 문제 합

Ljunhyeob - App Dev 2023. 1. 5. 14:07

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

 

8393번: 합

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

www.acmicpc.net

 

https://github.com/Ljunhyeob/baekjoon8393

 

GitHub - Ljunhyeob/baekjoon8393: 백준 - 8393

백준 - 8393. Contribute to Ljunhyeob/baekjoon8393 development by creating an account on GitHub.

github.com

//
//  main.swift
//  baekjoon8393
//
//  Created by 이준협 on 2023/01/04.
//

import Foundation
let line = readLine()!

let num = Int(line)!
var total = 0

for i in 1...num{
    total = total + i
}
print(total)
Comments