#define _CRT_SECURE_NO_WARNINGS 1
/ ****
- @Title:> Jour12
- @Description:> Récursivité
- @auteur:> HuaGe
- @date:> 2020/10/20 18:56
* ** /
// Récursivité
// # include <stdio.h>
//// Question: Acceptez une valeur entière et imprimez chaque bit dans l'ordre, comme entrée 123, sortie 1 2 3.
// void int_Print (int x)
/ / {
// if (x> 9) {
// int_Print (x / 10);
//}
// printf ("% d \ n", x% 10);
//}
//
// int main ()
// {
// printf ("Veuillez saisir un nombre entier:");
// int a;
// scanf ("% d", & a);
// int_Print (a);
//
// retourne 0;
// }
#include <stdio.h>
//// Rechercher la fonction de longueur de chaîne
// int my_StrLen (char arr)
// {
// int mark = 0;
// while ( arr! = '\ 0') {
// mark ++ ;
// arr ++;
//}
// marque de retour;
//}
//// Trouver la longueur de la chaîne de manière récursive
// 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);
//
// retourne 0;
//}
//// Utilisez la récursivité pour trouver la factorielle de 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);
//
// retourne 0;
//}
// Pour trouver la séquence de Fibonacci, il n'est pas bon d'utiliser la récursivité, et le calcul répété est trop grand.
int FeiB (int n)
{
int a, b;
a = 1;
b = 1;
int résultat = 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 = résultat;
}
retourne le résultat;
}
int main ()
{
int n = 6;
résultat int = FeiB (n);
printf ("% d \ n", résultat);
return 0;
}