C Program to find the factorial of any number.

 #include<stdio.h>


int factorial(int number)
{
    if (number==1 || number==0)
    {
        return 1;
    }
    else{
        return (number * factorial(number-1));
    }
   
}
int main()
{
    int num;
    printf("Enter the number you want the factorial of\n");
    scanf("%d", &num);
    printf("The factorial of %d is %d\n", num, factorial(num));
    return 0;
}

OUTPUT:
Enter the number you want the factorial of 3 The factorial of 3 is 6

Enter the number you want the factorial of
4

Enter the number you want the factorial of 0 The factorial of 0 is 1


Comments

Post a Comment

Popular posts from this blog

C Program using continue statement

C program of WHILE Loop

NULL Pointer in C.

C Program using DO WHILE loop

C Program using SWITCH statement

New Animated Login or signup page made by HTML, CSS and JavaScript.

C Program to print multiplication table of any number.

C Language Travel Agency Manager Exercise.

STRUCTURE IN C PROGRAMMING.