SARACEN's Blog
  • [C언어]Project Euler(프로젝트 오일러) 2 번
    2020년 08월 01일 23시 38분 10초에 업로드 된 글입니다.
    작성자: RACENI
    ::문제::
    피보나치 수열에서 4백만 이하이면서 짝수인 항의 합

    ::문제 주소::
    https://euler.synap.co.kr/problem=2

     

    -이하 소스 코드-

    #include <stdio.h>
    
    int main()
    {   
        int total = 0; // 정답 변수
        int count = 1;
    
        for(int i = 1; i <= 4000000; )
        {
            i = fibo(count);
            count++;
    
            if(i % 2 == 0)
            {
                total += i;
            }
        }
    
        printf("%d", total); // 4613732
    
        return 0;
    }
    
    int fibo(int num)
    {
        if (num == 0)
            return 0;
    
        else if (num == 1)
            return 1;
    
        else
            return fibo(num - 1) + fibo(num - 2);
    }
    댓글