0
I need to use function in C but is not returning the factorial.
Problem:"Given an integer n, calculate its factorial n!. The factorial of a number is given by the equation:
n! = n(n1)(n2) : : : 1. Por definição, 0! = 1.
You must implement the function:
1 /** 2 * Function that calculates the factorial of a number n
3 * @param n a positive integer
4 * @re-factorial of n
5 */
6 unsigned long int fat( unsigned int n);Input The program must read an integer number n. Output The program must display a line with the message: "n! = f", where n is the number read e f its factorial. Observations The factorial of a number is the result of a productive operation that can lead to incredibly high values great. Remember to use appropriate data types to the problem proposed."
My code:
#include <stdio.h>
#include <stdlib.h>
unsigned long int fat( unsigned int n){
int x,fatorial,resultado1;
for(fatorial = 0; x > 1; x = (x - 1)){
fatorial = (fatorial * x);
resultado1=fatorial;
}
return resultado1;
}
int main(){
int numero,resultado;
scanf("%d",&numero);
resultado = fat(numero);
printf("%d! = %d",numero,resultado);
return 0;
}
Thank you very much!
– Gabriel Santos