C语言递归的使用

(1)尾巴递归,什么时候递归结束.实现想要的递归终止条件.

(2)如何递归和返回想要的值  相加还是相减  return  xx*xx;

(3)递归函数的编写和递归调用和功能需求. 

 

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>


// 1+2+3+4+5
static int  fun(int n)
{
    if(n<=1000)
    {
        return n+fun(n+1);
    }
    else
    {
         return 0;
    }
}

int main()
{

    printf("%d\n",fun(1));
    for(;;);
    return 0;
}

  

posted @ 2020-09-20 22:03  卷哭你  阅读(430)  评论(0编辑  收藏  举报