/** C Program to find the Factorial of Given Number **/

#include <stdio.h>

//#include<conio.h>

int main()

{

int num,i,fact=1;

//clrscr();

printf("\n >> PROGRAM TO FIND FACTORIAL OF GIVEN NUMBER <<\n");

printf("\n Enter the Number whose Factorial you want: ");

scanf("%d",&num);

for(i=num; i>=2 ; i--) //i is intializing with num value and is decremented till 2

{

fact = fact * i; //fact is updating with changing value of i

}

printf("\n The factorial of %d is %d.\n\n",num,fact);

//getch();

return 0; //indicate end of program to OS

}

---------------------------------------------------

Sample Output:

( using GNU GCC Compiler with code::blocks IDE, hence no need of clrscr(); and getch(); )

Hey, I also have a very interesting program to calculate the factorial of any number, no matters whether the number is very large, like if you wish to calculate the factorial of 500, my program will calculate it, and even it gives each and every digit of the result. for details and source code visit http://codingloverlavi.blogspot.in/2013/03/here-is-one-more-interesting-program.html

ReplyDeletehope you would like it.

You can find some other simple programs for factorial on the following links:-

http://codingloverlavi.blogspot.in/2013/05/recursive-program-for-factorial.html

http://codingloverlavi.blogspot.in/2013/05/factorial-calculation-without-any.html

ReplyDeleteVery informative article.Thank you author for posting this kind of article .

http://www.wikitechy.com/view-article/c-program-to-find-factorial-of-a-number-with-example-and-explanation

Both are really good,

Cheers,

Venkat