/* C Program to find Factorial of given Number using Function*/

#include <stdio.h>

//#include<conio.h>

int main()

{

int num;

//clrscr();

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

using Function <<\n");

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

scanf("%d",&num);

printf("\n The factorial of %d is %d.\n\n",

num,factorial(num));

//factorial(num) prints the value returned by the function

//getch();

return 0;

}

int factorial(num1)

{

int i,fact=1;

for(i=num1; i>=2 ; i--)

{

fact = fact * i;

}

return fact; //returning fact to main function

}

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

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

Program is good. Working preety good. One suggestion include int factorial() instead of factorial to specify that we are returning a value of integer type.

ReplyDeleteSee this : Best c compiler for windows

Java programming tutorial

Good posting friend

Deletevisit http://javabelazy.blogspot.in/

for alternative methods.

Anyway I am just looking for the #Passionate #Programmers #Coders all who are interested in coding join me where i live @ Code For Win

ReplyDeletegood

ReplyDeleteGood Job By Admin....

ReplyDeleteI find one more easiest way to write

C Program To Find Factorial Of The Given Number by using single while loop

thank you so much for this tutorial

ReplyDeleteThis blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

ReplyDeleteLove from

it is nice code.

ReplyDeletesame program will also present in their also

http://www.techcrashcourse.com/2014/10/c-program-find-factorial-of-number.html

There's a similar code for Queues implemented in Linux OS. You should definitely check this out:

ReplyDeleteC Program For Queue using Array

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

but the above program doesn't work for factorial more than 25

ReplyDeleteor 27...

this is because, we are trying to store result in integer type, factorial of 25 gives a very big value, which is out of int capacity. try long or unsigned long and check once

Delete