문제 설명

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

 

풀이

#include <iostream>

using namespace std;

int main() {
	int num, total = 0;

	cin >> num;

	for (int i = 1; i <= num; i++)
		total += i;

	cout << total << endl;

	return 0;
}

'백준 > 반복문' 카테고리의 다른 글

15552: 빠른 A + B / C++  (0) 2023.03.07
25314: 코딩은 체육과목 입니다 / C++  (0) 2023.03.07
25304: 영수증 / C++  (0) 2023.03.07
10950: A + B - 3 / C++  (0) 2023.03.07
2739: 구구단 / C++  (0) 2023.03.07

+ Recent posts