C Program to find Factorial of any Number.

C Program to find Factorial of any number.

In mathematics, the factorial of the whole number 'n' denoted by 'n!' is defined as the product of all the positive integers equal to or less than the given positive number "n"

The Formula of the factorial of any number was: -

n! = n * (n-1) * (n-2) * ....... 3 x 2 x 1.

For Example :- 

5! = 5 X 4 X 3 X 2 X 1 = 120.

You can also write it as 

5! = 5 X 4! = 120

Whatever we saw above was is in maths. Now we will see this through c programming. How would this formula be used in c programming? 

Source Code :-

int i,n,fac=1;
printf("Enter the Number");
for (i=n;i>=1;--i)

Explanation of the code: - 
  • In this code, we simply get three integer containers ( i, n, fac ) respectively. we have already defined int fac value which is 1
  • Now after that, we entered a number by the user. we have placed it on the int n. 
  • After it, we applied a loop and the loop is running nth time until the value of the n is equal to 1.
  • Every time the value of the i is decreased whenever the loop run.
  • After the loop end, the product of all the numbers is stored on the int fac.
  • At the end of the program, we have got the result as output.
Output: - 

  • '+w+""+y+"
  • "}else{if(A==6){c+='
  • "+w+'
  • "}else{c+='
  • "+w+"
  • "}}}}}s.innerHTML=c+=""+y;d.callBack()};randomRelatedIndex=h;showRelatedPost=g;j(d.homePage.replace(/\/$/,"")+"/feeds/posts/summary"+e+"?alt=json-in-script&orderby=updated&max-results=0&callback=randomRelatedIndex")})(window,document,document.getElementsByTagName("head")[0]); //]]>


    Post a Comment

    Follow on Twitter



    Mad About Computer. Powered by Blogger.
    This site is in no way affiliated with or endorsed by specified business. It exists as a compendium of supporting information intended for informational purposes only. If you want to buy this website, please don't hesitate to contact us via e-mail: "d e n a c c 9 7 7 (at) g m a i l (dot) c o m" (delete spaces) or you can find and buy it on Afternic domain auctions.