Search Your C Program

Tuesday 7 February 2012

Program to calculate the factorial of a number.

#include<stdio.h>
#include<conio.h>
void main()
{
                int n,i=1,fact=1;
                clrscr();
                printf("\n Enter  a number ");
                scanf("%d",&n);
                while(i<=n)
                {
                                fact=fact * i;
                                i++;
                 }
                 printf("\n Factorial of  %d = %d",n,fact);
                 getch();
}


NOTE :=  Factorial of a number can be calculated  as
                  5! = 5 * 4 * 3 * 2 * 1 = 120.

No comments:

Post a Comment