U E D R , A S I H C RSS

피보나치/김정현

~cpp 
#include <iostream>
using namespace std;

int fibonach(int num);

void main()
{
	int input;
	cout<<"숫자를 입력해봐요\n";
	cin>>input;		
	cout<<input<<"번째 피보나치 수열은 "<<fibonach(input)<<"\n";
}

int fibonach(int num)
{
	if(num<=1) return num;
	return fibonach(num-1)+fibonach(num-2);
}

~cpp 
//파이선으로 작성

def fibonach(a):
    if a<=1:
        return a
    return fibonach(a-1) + fibonach(a-2)

if __name__ == '__main__':
    
    a=int(raw_input("input number"))
    print fibonach(a)
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:27
Processing time 0.0095 sec