2
I can’t fix the error of the last "factorial" function, which in this case would be the factorial at the bottom of this calculation:
Program:
#include <stdio.h>
#include <conio.h>
double fatorial(int n);
double fatorial2(int x, int y);
int main()
{
int n;
int k;
double A;
printf("Digite os valores de N e K: ");
scanf("%d", &n);
scanf("%d", &k);
A = (float)fatorial(n) / fatorial2(n, k);
printf("Fatorial = %.0lf", A);
getch();
return 0;
}
double fatorial(int n)
{
double cima;
if ( n <= 1 )
return (1);
else
{
cima = n * fatorial(n - 1);
return (cima);
}
}
double fatorial2(int x, int y)
{
double baixo;
if ( (x <= 1) && (y <= 1))
return (1);
else
{
baixo = (x - y) * fatorial2((x - y) - 1);
return (baixo);
}
}
And what mistake you’re making?
– prmottajr
The function signature in the question asks to return
int
naydouble
. I take advantage and reinforce the question of @prmottajr , what the error? What is happening or failing to happen?– Jefferson Quesado
the function I quoted is giving error, and displaying the following message "Little argument for the factorial function2'"
– WeslleyAF
I cannot understand why you have implemented two factorial functions when you can just use one, doing
A = (float)fatorial(n) / fatorial(n - k);
– Isac
Nothing better than trying it out. Take your code and remove all references to the
fatorial2
, and just leave that line as I pointed out for the calculation ofA
, and make sure it is not the result you are looking for. Remember thatfatorial(n-k)
the parameter is 1 in the same, which is the subtraction between 2 values. Ifn
for10
andk
for4
will amount to doingfatorial(6)
– Isac
Damn, it worked... kkkkk
– WeslleyAF