강의

멘토링

커뮤니티

Inflearn Community Q&A

wohaonine1166's profile image
wohaonine1166

asked

Following and Learning C++ with Hong Jeong-mo

7.12 Recursive function calls

안녕하세요, 강의 너무 쉽고 이해 잘되네요!!

Written on

·

158

1

마지막에 피보나치 예제를 주셨는데 제가 코딩하니까 검은빈화면만 뜨고 아무것도 안되어 막혔습니다..

int pibonaci(int n)

 
 static int temp1 ;
 static int temp2 ;
 static int temp3 ;
 temp3 = temp1 + temp2;  //피보나치 수열 값들 저장할변수
 while (n == 1)  // 재귀함수로 반복되기전에 첫번째만 대입..
 {
  temp1 = 0; temp2 = 0; temp3 = 1;
 }
 
 cout << t3 << "\t";
 t1 = t2;
 t2 = t3;
 cout << "pibonaci's [" << n << "] th count complete." << endl;
 if (n == 20)        // 20번째까지만 재귀함수 출력
  goto sodone;
 pibonaci(n + 1);
sodone:
 return 100;
}

int main()
{
 pibonaci(1);

//n 은 피보나치 수열의 n 번째 라는 표시입니다.

// 0 0 1 1 2 3 5 8 13 ....

}
문제가 무엇일까요? 아시는 수강생께도 여쭤봅니다 ㅠㅠ

C++

Answer 1

2

honglab님의 프로필 이미지
honglab
Instructor

안녕하세요? 원래 처음할 때는 어렵습니다. goto는 사용하지 않으시는 것을 권장합니다.

 

wohaonine1166's profile image
wohaonine1166

asked

Ask a question