9/05/2011

What is a Recursive Call? and Make Fibonacci sequence function using Function of the Recursive Call type.

Recursive call is that this method call oneself.
Specially, Function uses this method.
Below C Source is example for recursive call function.
As you see, Function RF called the RF that is name of oneself.

Now I give you one question.
Please make Fibonacci sequence function using recursive call method.

You can see Fibonacci condition <here>

The LINUX that is name of OS is also recursive call type.
Some people said " LINUX is abbreviation of LINUX is not UNIX. "
Here, LINUX is call LINUX is not UNIX. In this sentence, LINUX is call LINUX is not UNIX again..
so..like that

(((((LINUX is not UNIX) is not UNIX) is not UNIX) is not UNIX) is not UNIX) is not UNIX

This case sink into the infinity roof because there is not escape condition. so we have to be careful when we use recursive call.

<English is very difficult.. Plz someone correct my poor sentence.>

์žฌ๊ท€ํ˜ธ์ถœ์ด๋ž€ ์ž๊ธฐ๊ฐ€ ์ž๊ธฐ์ž์‹ ์„ ํ˜ธ์ถœํ•˜๋Š” ๋ฐฉ์‹์„ ๋งํ•œ๋‹ค.
ํŠนํžˆ ํ•จ์ˆ˜์—์„œ ์ด๋Ÿฐ ์ผ์„ ํ•œ๋‹ค.
์ด๋Ÿฐ ์žฌ๊ท€ํ˜ธ์ถœ ํ•จ์ˆ˜๊ฐ€ ํ•„์š”ํ•œ ๊ฒฝ์šฐ๋Š”
์–ด๋–ค ์ผ์„ ํ•˜๋Š” ํ•จ์ˆ˜๊ฐ€ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์กฐ๊ฑด์— ๋Œ€ํ•˜์—ฌ ๋˜‘๊ฐ™์€ ์ผ์„ ํ•  ํ•„์š”๊ฐ€ ์žˆ์„ ๋•Œ์ด๋‹ค.
๊ทธ๋Ÿฐ๋ฐ ๋‹ค์‹œ ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์กฐ๊ฑด์ด ์ฃผ์–ด์ง€๊ณ  ๋˜๋‹ค์‹œ ๊ฐ™์€ ์ผ์„ ํ•ด์•ผํ•  ๋•Œ ์žฌ๊ท€ ํ˜ธ์ถœ ํ•จ์ˆ˜๋ฅผ ์“ด๋‹ค.
์ด๊ฑด ๋ง๋กœ ํ‘œํ˜„ํ•˜๊ธฐ ๋ฌด์ฒ™ ์–ด๋ ต๋‹ค.. ใ…Žใ…Ž

ํ•œ๊ฐ€์ง€ ์˜ˆ์ œ๋ฅผ ๋ณด์ž

----------------------------------------------

int RF(int A);

void main()
{
printf("%d\n", RF(5) );
}


int RF(int A)
{
int B=0;
if(A>1)
{
B = RF(A-1);
}

return A+B;
}

------------------------------------------------

RFํ•จ์ˆ˜๋Š” 1์—์„œ ์ž…๋ ฅ๋œ ์ˆซ์ž๊นŒ์ง€ ๋”ํ•˜๋Š” ํ•จ์ˆ˜์ด๋‹ค.
RFํ•จ์ˆ˜๋ฅผ ๋ณด๋ฉด ๋ณธ๋ฌธ์•ˆ์— ๋‹ค์‹œ ์ž๊ธฐ ์ž์‹ ์„ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
์ด๋Ÿฐ ๋ฐฉ๋ฒ•์„ ์žฌ๊ท€ํ˜ธ์ถœ์ด๋ผ๊ณ  ํ•œ๋‹ค.

์—ฌ๊ธฐ์„œ ๋ฌธ์ œ๊ฐ€ ๋‚˜๊ฐ‘๋‹ˆ๋‹ค.
์ด๋Ÿฐ ์žฌ๊ท€ํ˜ธ์ถœ ๋ฐฉ์‹์„ ์ด์šฉํ•˜์—ฌ ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜์—ด์˜ ๊ฐ’์„ ๊ตฌํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ ๊ตฌํ˜„ํ•ด ๋ณด์‹œ์˜ค.
์ด๋ฒˆ์—๋Š” ์ข€ ์–ด๋ ค์šธ ๊ฑธ.. ใ…‹ใ…‹


์ด๋Ÿฐ ๊ฒƒ๋„ ์žฌ๊ท€ ํ˜ธ์ถœ์ผ๊นŒ?
LINUX ๋ผ๋Š” ์šด์˜์ฒด์ œ๊ฐ€ ์žˆ๋‹ค.
๊ทธ๋Ÿฐ๋ฐ ์ด๊ฒƒ์€ LINUX is not UNIX์˜ ์•ฝ์ž๋ผ๊ณ  ํ•œ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์—ฌ๊ธฐ์„œ LINUX๋Š” ๋‹ค์‹œ LINUX is no UNIX๋ฅผ ๋งŒ๋“ ๋‹ค.

๋”ฐ๋ผ์„œ ..
(((((LINUX is not UNIX) is not UNIX) is not UNIX) is not UNIX) is not UNIX) is not UNIX

LINUX is not UNIX์—์„œ LINUX๊ฐ€ ๊ณ„์† LINUX is not UNIX๋ฅผ ์ƒ์„ฑํ•ด ๋‚ธ๋‹ค..
์ด๋ ‡๋“ฏ ์žฌ๊ท€ํ˜ธ์ถœ์€ ์กฐ๊ฑด ๋ฌธ์œผ๋กœ break๋ฅผ ์ž˜ ํ•ด์ฃผ์ง€ ์•Š์œผ๋ฉด ๋ฌดํ•œ ๋ฃจํ”„์— ๋น ์ง€๊ธฐ ์‰ฝ๋‹ค..











6 comments:

  1. Anonymous5/9/11 23:26

    ๋ฏผํ˜„๊ทœ
    #include
    int fi(int n);

    void main()
    {
    printf("%d\n",fi(11));
    }


    int fi(int n)
    {

    int a=0;
    int b=1;
    if(n>2)
    {
    a=fi(n-2);
    b=fi(n-1);
    }
    return a+b;

    }

    ReplyDelete
  2. Anonymous6/9/11 00:41

    JeKang's Code :

    #include

    int fiv(int Num);

    int main()
    {
    int Num=0;
    scanf("%d", &Num);
    printf("%d",fiv(Num));
    }

    int fiv(int Num)
    {
    int Answer=0;
    if(Num==0) return 0;
    else if(Num==1) return 1;
    else if(Num>1){
    Answer=fiv(Num-2)+fiv(Num-1);
    return Answer;
    }
    }

    ReplyDelete
  3. Anonymous6/9/11 00:44

    ์ˆ˜์ • ๋ฏผํ˜„๊ทœ
    #include

    int fi(int n);

    void main()
    {
    int n;
    printf("ํ”ผ๋ณด๋‚˜์น˜์ˆ˜์—ดfi(n):");
    scanf("%d",&n);
    printf("%d\n",fi(n));
    }


    int fi(int n)
    {

    int a=0;
    int b=1;
    if(n>=2)
    {
    a=fi(n-2);
    b=fi(n-1);
    return a+b;
    }
    else if(n==0) return a;
    else if(n==1) return b;

    }

    ReplyDelete
  4. #include


    int RecursiveF(int n);


    void main()
    {

    int x=20;
    for(int i=0; i<x; ++i)
    {
    printf("f(%d) = %d\n", i, RecursiveF(i) );
    }
    }



    int RecursiveF(int n)
    {
    if(n==0)
    return 0;

    if(n==1)
    return 1;

    return (RecursiveF(n-2) + RecursiveF(n-1));
    }

    ReplyDelete
  5. ๋‹ค๋“ค ์ž˜ํ–ˆ๋‹ค.
    ์–ด๋•Œ? ๋ฐ˜๋ณต์  ๋ฐฉ๋ฒ•๊ณผ ์žฌ๊ท€ํ˜ธ์ถœ์  ๋ฐฉ๋ฒ•์ค‘ ์–ด๋–ค๊ฒŒ ํ”„๋กœ๊ทธ๋žจ ํ•˜๊ธฐ ํŽธํ•œ๊ฒƒ ๊ฐ™์•„?(์ž๊ธฐ ์ƒ๊ฐ ์ฝ”๋ฉ˜ํŠธ ํ•˜๋‚˜์”ฉ ๋‹ฌ๊ธฐ~)
    ...
    ํ•˜์ง€๋งŒ ์žฌ๊ท€ํ˜ธ์ถœ ๋ฐฉ๋ฒ•์€ ๋ฐ˜๋ณต์ ์ธ ๋ฐ˜๋ณต๋ณด๋‹ค ํ”„๋กœ๊ทธ๋žจ์— ๋ถ€๋‹ด์„ ๋งŽ์ด ์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด์•ผ.. ์™œ๋ƒํ•˜๋ฉด ํ•จ์ˆ˜์•ˆ์— ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœ.. ๋˜ ๋‹ค์‹œ ํ•จ์ˆ˜ ํ˜ธ์ถœ.. ์ด๋ ‡๊ฒŒ ์•ˆ์œผ๋กœ ๋“ค์–ด๊ฐˆ์ˆ˜๋ก ํ”„๋กœ๊ทธ๋žจ์€ ๊ธฐ์–ตํ• ๊ฒŒ ๋งŽ์•„์ง€๊ฑฐ๋“ .
    ํ•จ์ˆ˜๋ฅผ ๋งˆ์ณค์„๋•Œ ๋Œ์•„๊ฐ€์•ผํ•˜๋Š” ์œ„์น˜ ๊ทธ๋ฆฌ๊ณ  ๊ณ„์† ์ƒ์„ฑ๋˜๋Š” ์ง€์—ญ ๋ณ€์ˆ˜๋“ค(ํ˜ธ์ถœ๋œ ํ•จ์ˆ˜๊ฐ€ ๋๋‚˜๊ธฐ์ „๊นŒ์ง€ ํ•จ์ˆ˜์•ˆ์— ๋ณ€์ˆ˜๋“ค์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ฐจ์ง€ํ•จ)..
    ๊ทธ๋ž˜์„œ ๋˜๋„๋ก ์žฌ๊ท€ํ•จ์ˆ˜๋Š” ์•ˆ์“ฐ๋Š”๊ฒŒ ์ข‹์ง€๋งŒ ์ปดํ“จํ„ฐ ์„ฑ๋Šฅ์— ๋ฌด๋ฆฌ๋ฅผ ์•ˆ์ค€๋‹ค๋ฉด ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๊น”๋”ํ•˜๊ฒŒ ์™„์„ฑ์‹œํ‚ฌ์ˆ˜ ์žˆ์ง€..
    ๊ทธ๋ฆฌ๊ณ  ์žฌ๊ท€ํ˜ธ์ถœ์€ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ณต๋ถ€ํ• ๋•Œ ๋…ผ๋ฆฌ์  ์‚ฌ๊ณ ๋ฅผ ํ‚ค์šฐ๊ธฐ ์œ„ํ•ด ์ข‹์€ ๋ฐฉ๋ฒ•์ธ๊ฒƒ ๊ฐ™๋‹ค..

    ๊ทธ๋Ÿผ ๋ฟ…~

    ReplyDelete
  6. Anonymous7/9/11 03:28

    ์žฌ๊ท€ํ˜ธ์ถœ ๋ฐฉ๋ฒ•์€ ์ด๋ฒˆ์— ์ฒ˜์Œ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ํ•ด๋ด์„œ ๊ทธ๋Ÿฐ์ง€ ๋ชจ๋ฅด๊ฒ ๋Š”๋ฐ ๋ฐ˜๋ณต๋ฌธ์ด ํ›จ์”ฌ ํŽธํ•œ๊ฑฐ ๊ฐ™์•„์š”. ์œ„์— ํ˜•๋‹˜์ด ์ ์–ด๋‘์‹ ๊ฑฐ ์ฒ˜๋Ÿผ ํ•จ์ˆ˜์•ˆ์— ํ•จ์ˆ˜์•ˆ์— ํ•จ์ˆ˜... ๊ณ„์† ํ˜ธ์ถœํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ˜ธ์ถœ ์œ„์น˜์— ๋”ฐ๋ผ ๊ฒฐ๊ณผ๋ฅผ ์˜ˆ์ƒํ•˜๊ธฐ๊ฐ€ ๋„ˆ๋ฌด ํž˜๋“ค์—ˆ์–ด์š”.

    ๋…ผ๋ฆฌ์  ์‚ฌ๊ณ ๋ฅผ ํ‚ค์šฐ๋Š”๋ฐ๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์ธ๊ฑฐ ๊ฐ™์€๋ฐ, ์žฅ์ ๋ณด๋‹ค๋Š” ๋‹จ์ ์ด ๋งŽ์•„์„œ ์•„์ง ์ดˆ๋ณด์ธ ์ €๋Š” ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๋งŒ๋“œ๋Š”๊ฒŒ ์ข‹์€๊ฑฐ ๊ฐ™์•„์š”.ใ…Žใ…Ž

    ReplyDelete