To find the factorial of given number using while loop

 Program:

#include<stdio.h>
#include<conio.h>
void main()
{
    int n;
    unsigned long fact=1;
    clrscr();
    printf("Enter a Number : ");
    scanf("%d", &n);
    while(n>=1)
    {
        fact = fact*n;
        n--;
    }
    printf("\n\nFactorial of %d is %lu", n, fact);
    getch();
}

Output:

Enter a Number : 5

Factorial of 5 is 120



Next Topic        :  

Previous Topic :

No comments:

Post a Comment