Thursday, June 17, 2010

Factorial

#include<stdio.h>

main()
{
   int num,i;
   long int fact;
   clrscr();
   printf("Enter a No. for finding factorial\n");
   scanf("%d",&num);
 
   if(num<0)
   {
     printf("\n%d Factorial Not Defined.\n",num);
   }
   else
   {
     fact=1;
     for(i=1;i<=num;i++)
     {
       fact=fact*i;
     }
     printf("\n%d Factorial=%d\n",num,fact);
   }
}

Output------>

No comments: