TIL_6주차(2) 코드카타: 알고리즘

원진·2025년 1월 21일

알고리즘

  1. 두 정수 사이의 합
    풀이:
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>

long long solution(int a, int b) {
    long long answer = 0;
    long long temp = 0;
    
    if(a>b){
        temp = a;
        a = b;
        b = temp;
    }
    for(int i = a; i <=b; ++i) answer +=i;
    return answer;
}

두 정수 사이의 합

0개의 댓글