Error in one of the functions of the program that calculates a factorial

2

I can not fix the error of the last "factorial2" function, which in this case would be the factorial at the bottom of this calculation:

Program:

#include<stdio.h>#include<conio.h>doublefatorial(intn);doublefatorial2(intx,inty);intmain(){intn;intk;doubleA;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);
    }
}
    
asked by anonymous 01.05.2018 / 18:56

1 answer

2

Test this way here:

#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 o valor de N: ");
  scanf("%d", &n);
  printf("\nDigite o valor de K: ");
  scanf("%d", &k);


  A = (float)fatorial(n) / fatorial2(n, k);

  printf("\nFatorial = %.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) * (fatorial((x-y)-1));
      return (baixo);
   }
}
    
01.05.2018 / 19:43