Skip to main content

Finding Factorial of a number | C programming

 Q.6    WAP in C/ C++/ java to find the factorial of the number.


Solution : 

#include<stdio.h>

void main()
{
    int n;
    printf("\nEnter any positive number : ");
    scanf("%d"&n);

    if (n<0)
    {
        printf("\nInvalid input! Enter the value again -->");
        main(); // calls the main() function again
    }
    else
    {
        int fact=1;
        for(int i=1i<=ni++)
        {
            fact=fact*i;
        }
        printf("Factorial is %d\n"fact);
    }
// end of main()


Comments