#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
 #include<string.h>
 //编写函数,不允许创建临时变量,求字符串长度
 ///1、可以使用临时变量的写法:
 //int my_strlen(char* str)
 //{
 //    int count = 0;
 //    while (*str != '\0')
 //    {
 //        count++;
 //        str++;
 //    }
 //    return count;
 //}
 //2、不适用临时变量,使用递归的写法:
//int my_strlen(char* str)
 //{
 //    if (*str != '\0')
 //        return 1 + my_strlen(str + 1);
 // //这里不允许写成str++或++str。因为str++是先输出str再++。括号内的值会变成str++的值。结果是错误的。
 //    else
 //        return 0;
 //}
 //
 // int main()
 //{
 //     char arr[] = { "hello world" };
 //
 //     //printf("%d\n", strlen(arr));//一般使用strlen函数求字符串长度。
 //
 //     printf("%d\n", my_strlen(arr));
 //
 //    return 0;
 //}
//函数递归与迭代
 //C语言中,循环语句也是一种迭代。
//计算n的阶乘:
 //正常写法:使用循环语句
//int main()
 //{
 //    int n = 0;
 //    scanf("%d", &n);
 //    int i = 0;
 //    int ret = 1;
 //    for (i = 1;i <= n;i++)
 //    {
 //        ret = ret * i;
 //    }
 //    printf("%d\n", ret);
 //    return 0;
 //}
//使用递归写法:
 //int Fac(int n)
 //{
 //    if (n <= 1)
 //        return 1;
 //    else
 //        return n * Fac(n - 1);
 //}
 //
 //int main()
 //{
 //    int n = 0;
 //    scanf("%d", &n);
 //    int ret = Fac(n);
 //    printf("%d\n", ret);
 //    return 0;
 //}
//求n的阶乘即可以使用递归,也可以使用迭代的方式进行计算。
//求第n个斐波那契数的值,不考虑溢出;
 // 
 // 1、使用公式直接套用到函数中,可以使用,但是效率特别低。如果n输入40,需要计算的次数为39088169次。
 // 
 // int count = 0;
 // 
 //int Fib(int n)
 //{
 //  if (n == 3)
 //  count++;
 //    if (n <= 2)
 //        return 1;
 //    else
 //        return Fib(n - 1) + Fib(n - 2);
 //}
//在函数中不使用递归,而是使用迭代的写法,会大大提高效率。(循环语句也是一种迭代)。
 //int Fib(int n)
 //{
 //    int a = 1;
 //    int b = 1;
 //    int c = 1;
 //    while (n < 2)
 //    {
 //        c = a + b;
 //        b = a;
 //        a = c;
 //    }
 //    return c;
 //}
 //
 //int main()
 //{
 //    int n = 0;
 //    scanf("%d", &n);
 //    int ret = Fib(n);
 //    printf("%d\n", ret);
 //    //printf("count = %d\n", count);
 //    return 0;
 //}