Algorithm/Solution
[프로그래머스] 두 정수 사이의 합
BeNI
2021. 8. 10. 16:56
728x90
코딩테스트 연습 - 두 정수 사이의 합 | 프로그래머스 (programmers.co.kr)
간단한 문제라 생략
#include <string>
#include <vector>
using namespace std;
long long solution(int a, int b) {
long long answer = 0;
long long tmp;
if(a>b){
tmp = a;
a = b;
b = tmp;
}
for(int i=a;i<=b;i++){
answer+=i;
}
return answer;
}
728x90