ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

find the factorial of a given number using c programming

Updated on March 24, 2010

To find the factorial of number, multiply continuously from 1 to that number.

for eg:- Factorial of 3 (ie. 3!) = 1 * 2 * 3 = 6

Factoria of 5 (ie. 5!) = 1 * 2 * 3* 4* 5 = 120

and so on.

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

#include<stdio.h>

#include<conio.h>

void main()

{

int f=1,i,n;

clrscr();

printf("Enter a number\n");

scanf("%d",&n)

while(i<=n)

{

f=f * i;

i=i+1;

}

printf("Factorial of %d is %d",n,f);

getch();

}

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

NB: stdio.h -------------> header file

conio.h ----------> heade file

int f=1 ----------> variable declaration & assigning values

scanf ---------------> getting value to the variable n from keyboard

f=f*i ----------------> value of f is multiplied by the value of i and save the result in to f.

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

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      thajuudin 5 years ago

      out put is 1 for every number witgh dz program

    • profile image

      Tamanna Jain 3 years ago

      Incorrect program

    • profile image

      agarwal 3 years ago

      Incorrect coding

    • profile image

      k.d.shukla 3 years ago

      it does not work for long integers

    • profile image

      Somnath Karmakar 3 years ago

      This is a bad programme ever ... so this is wrong please don't copy this anywhere;;;;;;;;; bogaaaaaaaaaassssssss

    • profile image

      Johna86 3 years ago

      Really informative article post.Thanks Again. Awesome. dfedcdadbbee

    • profile image

      Pharmd588 2 years ago

      Very nice site! cheap goods http://yieopxa2.com/yxyaovx/4.html

    • profile image

      blaze 2 years ago

      abe kabhi jindhgi mai program banaye tha kya

    • profile image

      Mantu 2 years ago

      Your program is wrong. intialize i=1 above while loop. Then the program will execute correctly.

      See this : http://www.comp-psyche.com/2014/03/best-c-compiler...

      http://www.java-programming-tutorial.com/2014/07/j...

    • profile image

      baba 2 years ago

      sahi hai bhai bawkoof bnana raha hai

    • profile image

      u.h shukla 2 years ago

      Best programs

    • profile image

      ashish 2 years ago

      wrong program

    • profile image

      ABC 2 years ago

      JHATU PROGRAM

    • profile image

      A.b 2 years ago

      ok ,this is correct;

    • profile image

      ashok rana 2 years ago

      Nice program

    • profile image

      raj 2 years ago

      Isko program banane nahi aate ...

      Aajaate hai program likhne...

    • profile image

      Guru 2 years ago

      Superb program

    • profile image

      indumathy 2 years ago

      very usefull for me

    • profile image

      abi 2 years ago

      nice

    • profile image

      deepak 2 years ago

      Not bad

    Click to Rate This Article