find the factorial of a given number using c programming

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.

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

More by this Author


Comments 20 comments

thajuudin 4 years ago

out put is 1 for every number witgh dz program


Tamanna Jain 3 years ago

Incorrect program


agarwal 2 years ago

Incorrect coding


k.d.shukla 2 years ago

it does not work for long integers


Somnath Karmakar 2 years ago

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


Johna86 2 years ago

Really informative article post.Thanks Again. Awesome. dfedcdadbbee


Pharmd588 2 years ago

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


blaze 2 years ago

abe kabhi jindhgi mai program banaye tha kya


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


baba 2 years ago

sahi hai bhai bawkoof bnana raha hai


u.h shukla 2 years ago

Best programs


ashish 2 years ago

wrong program


ABC 2 years ago

JHATU PROGRAM


A.b 2 years ago

ok ,this is correct;


ashok rana 23 months ago

Nice program


raj 23 months ago

Isko program banane nahi aate ...

Aajaate hai program likhne...


Guru 22 months ago

Superb program


indumathy 21 months ago

very usefull for me


abi 21 months ago

nice


deepak 21 months ago

Not bad

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working