최대 1 분 소요

[공지사항]지킬블로그 신규 업데이트 안내드립니다

공지사항

  • 공지 사항 순서 1
  • 공지 사항 순서 2
  • 공지 사항 순서 3

버튼입니다

와우~

오늘 처음 블로그를 만들었습니다.

앞으로 열심히 할게요!

이게 왜 안됄까

code


#include <iostream>
using namespace std;

int main() {
    int n, t1 = 0, t2 = 1, nextTerm = 0;

    cout << "Enter the number of terms: ";
    cin >> n;

    cout << "Fibonacci Series: ";

    for (int i = 1; i <= n; ++i) {
        // Prints the first two terms.
        if(i == 1) {
            cout << t1 << ", ";
            continue;
        }
        if(i == 2) {
            cout << t2 << ", ";
            continue;
        }
        nextTerm = t1 + t2;
        t1 = t2;
        t2 = nextTerm;
        
        cout << nextTerm << ", ";
    }
    return 0;
}

태그: ,

카테고리:

업데이트:

댓글남기기