C Program to find Factorial of given Number using Function
/* C Program to find Factorial of given Number using Function */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#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; } 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
hope 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