C language learning Day12

#define _CRT_SECURE_NO_WARNINGS 1

/****

  • @Title:> Day12
  • @Description:> Recursion
  • @author:> HuaGe
  • @date:> 2020/10/20 18:56
    ***/

//Recursion
//#include<stdio.h>
////Question: Accept an integer value and print each bit of it in order, such as input 123, output 1 2 3.
//void int_Print(int x)
/ /{
// if (x> 9) {
// int_Print(x / 10);
//}
// printf("%d\n", x% 10);
//}
//
//int main()
//{
// printf("Please enter an integer number:");
// int a;
// scanf("%d", &a);
// int_Print(a);
//
// return 0;
// }

#include<stdio.h>
////Find the string length function
//int my_StrLen(char arr)
//{
// int mark = 0;
// while (
arr !='\0'){
// mark++ ;
// arr++;
//}
// return mark;
//}

////Find the length of the string in a recursive way
//int my_StrLen(char arr)
//{
// if (
arr !='\0') {
// return my_StrLen(arr+1) + 1;
// }
// else {
// return 0;
//}
//}
//
//int main()
//{
// char arr[] = "ertere";
// int len ​​= my_StrLen(arr);
// printf("%d\n", len);
//
// return 0;
//}

////Use recursion to find the factorial of n
//int jieCheng(int n)
//{
// if (n == 1) {
// return 1;
//}
// else {
// return n * jieCheng( n-1);
//}
//}
//
//int main()
//{
// int n = 4;
// int result = jieCheng(n);
// printf("%d\n", result);
//
// return 0;
//}

//To find the Fibonacci sequence, it is not good to use recursion, and the repeated calculation is too large.
int FeiB(int n)
{
int a, b;
a = 1;
b = 1;
int result = 1;
//printf("a=%d\tb=%d\tc=%d\n", a, b, c);
/ if (n == 1 || n == 2) {
return 1;
}
/
for (int i = 2; i <n; i++) {
result = a + b;
a = b;
b = result;
}
return result;
}

int main()
{
int n = 6;
int result = FeiB(n);
printf("%d\n", result);

return 0;

}

Guess you like

Origin blog.51cto.com/14947752/2542680