ahmed149 / learning-programing-in-C

0 stars 0 forks source link

ALX: a function that returns the factorial of a given number (factorial) #52

Open ahmed149 opened 1 year ago

ahmed149 commented 1 year ago

include "main.h"

/**

result = factorial(n - 1);: Here, it calculates the factorial of n by making a recursive call to the factorial function with the argument n - 1. This recursive call calculates the factorial of the number one less than the current n and multiplies it with n (the current value of result). This process continues recursively until it reaches the base cases of n < 0 or n <= 1./ result *= factorial(n - 1);

return (result);

}

ahmed149 commented 1 year ago

include

int main(void) { // your code goes here int num; int i =1; scanf("%d",&num); for(int a = 1; a <= num; a = a + 1 ) { i = i * a; } printf("The factorial of the given number is: %d",i); return 0; }