Calcul l'exponentiel par recursivité
amjad63
Messages postés
31
Statut
Membre
-
gael31390 Messages postés 734 Statut Membre -
gael31390 Messages postés 734 Statut Membre -
Bonjour,
por qui cherche comment calcul l'exponentiel par recursivité , voila le solution
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int factoriel(int n, int i, int fact)
{
if(i==n+1)
{
return fact;
}
else
{
fact = fact*i;
i++;
fact=factoriel(n,i,fact);
}
}
int puissance(int n, int i, float x, float p)
{
if(i==n+1)
{
return p;
}
else
{
p=p*x;
i++;
p=puissance(n,i,x,p);
}
}
int main()
{
const float EPS=0.000000000001;
int i, n, fact;
float x,p,s,T;
printf("Donner x: ");
scanf("%f", &x);
n=0; T=1; s=0; fact=1; p=1;
while(floor(T) > EPS)
{
T=puissance(n,1,x,p)/factoriel(n, 1, fact);
s=s+T;
n=n+1;
}
printf("Exp(%f) = %f\n", x, s);
}
por qui cherche comment calcul l'exponentiel par recursivité , voila le solution
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int factoriel(int n, int i, int fact)
{
if(i==n+1)
{
return fact;
}
else
{
fact = fact*i;
i++;
fact=factoriel(n,i,fact);
}
}
int puissance(int n, int i, float x, float p)
{
if(i==n+1)
{
return p;
}
else
{
p=p*x;
i++;
p=puissance(n,i,x,p);
}
}
int main()
{
const float EPS=0.000000000001;
int i, n, fact;
float x,p,s,T;
printf("Donner x: ");
scanf("%f", &x);
n=0; T=1; s=0; fact=1; p=1;
while(floor(T) > EPS)
{
T=puissance(n,1,x,p)/factoriel(n, 1, fact);
s=s+T;
n=n+1;
}
printf("Exp(%f) = %f\n", x, s);
}
A voir également:
- Calcul l'exponentiel par recursivité
- Calcul km marche à pied gratuit - Télécharger - Sport
- Calcul moyenne excel - Guide
- Calcul charpente bois gratuit - Télécharger - Architecture & Déco
- Logiciel gratuit calcul valeur nutritionnelle - Télécharger - Santé & Bien-être
- Logiciel gratuit calcul surface m2 - Télécharger - Outils professionnels
3 réponses
pk le mien ne marche pas, a la ligne 25 il me dit : [Warning] converting to 'int' from 'float'
alors qu'a la ligne 25 c'est : " return p; "
alors qu'a la ligne 25 c'est : " return p; "