백준 쉽게 푸는 문제

hyun20·2021년 7월 11일
0
#include <iostream>
using namespace std;
int main() {
	int index = 0, arr[1000]; //배열과 인덱스
	int value = 1, count;//배열에 저장하는 값, (0~배열에 저장하는 값 )개수 셈
	while(value<46){
		count = 0;
		while (count < value) {
			arr[index] = value; 
			if (index == 999) break;
			index++; count++;
		}
		value++; //현재수+1의 수를 저장
	}
	int total = 0, start, end;
	cin >> start >> end;
	for (int i = start - 1; i < end; i++)
		total += arr[i];
	cout << total << endl;
}

0개의 댓글