Blog Moved

This website completely moved to new domain. For latest content, visit www.programmingposts.com

Search This Blog

17 Aug 2012

C Program to find the Factorial of Given Number


/** 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(); )


2 comments:

  1. 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

    ReplyDelete



  2. Very 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

    ReplyDelete