2012년 4월 4일 수요일

src] // 자바 재귀함수 이용 피보나치 수열


// 자바 재귀함수 이용 피보나치 수열

class Fibonacci {
 public static void main(String args[]) {
  int inputValue = (int) Integer.parseInt(args[0]); // 입력값
  int outputValue = 0; //출력값
  int counter;
  for (counter = 0; counter < inputValue; counter++) {
   outputValue = fibonacci(counter);
  }
  System.out.println("After " + counter + " months : " + outputValue
    + " rabbit pairs.");
 }
 static int fibonacci(int input) {
  if (input == 0) { // f(0) = 1
   return 1;
  }
  else if (input == 1) { // f(1) = 1
   return 1;
  }
  else if (input > 1) { // f(n) = f(n-1)+ f(n-2) (n>1경우) 일경우
   return fibonacci(input - 1) + fibonacci(input - 2);
  }
  else { // 그 외 값
   return -1;
  }
 }
}

댓글 없음:

댓글 쓰기

국정원의 댓글 공작을 지탄합니다.

대학원생의 투고 지도 ④ (완결) — 논문의 수준이란 무엇인가: 사다리와 사분위, 첫 논문 전략

완결편이다. "논문 수준"이라는 말을 해부하고, 에듀테크 석사생의 첫 논문 전략으로 마친다. 학위논문과 학술지 논문은 다른 장르다 먼저 가장 흔한 혼동부터. 학위논문(thesis)은 "내가 연구를 수행할 줄 안다...