웅재의 코딩세상

[프로그래머스] 두 정수 사이의 합 본문

코딩테스트/프로그래머스 - LV 1

[프로그래머스] 두 정수 사이의 합

웅드 2024. 2. 9. 17:26

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

long long solution(int a, int b) {
    long long answer = 0;
    int n=0;
    if(a>b) {
        n = b;
        b = a;
        a = n;
    }
    for(; a<=b; a++){
        answer += a;
    }
    return answer;
}
반응형