**What is a Factorial of a number 'n'?**

The factorial of a number 'n' is the product of all number from 1 upto the number 'n'it is denoted by n!. For example n=5 then factorial of 5 will be 1*2*3*4*5= 120. 5!= 120

**Factorial program C++ Logic:**

- First think what is the factorial of a number? How mathematically it can be calculated.
- If you got this info then it will be very easier to make a
**C++ Program logic to find the factorial.** **User enters a number and we have to multiply all numbers upto entered number.****Like if user enters 6 then Factorial should be equal to factorial= 1*2*3*4*5*6.**- In this case a for Loop will be very helpful. It will start from one and multiply all numbers upto entered number after it loop will be terminated.
- Take a variable and initialized it to 1 and in loop store multiplication result into it like in below program a variable
**Factorial is used for this purpose.**what is we does not initialized it to 1 and initialized it to zero or remain it uninitialized. In case of 0 our result will be zero in case of any number entered- In case of not initializing it our answer will correct mostly but if variable contains garbage value then we will not be able to get correct result.
**It is recommended that to initialize it to one.**

C++ code to find prime number using for loopC++ code to find prime number using for loop

#include<iostream>

using namespace std;

int main()

{

int num,factorial=1;

cout<<" Enter Number To Find Its Factorial: ";

cin>>num;

for(int a=1;a<=num;a++)

{

factorial=factorial*a;

}

cout<<"Factorial of Given Number is ="<<factorial<<endl;

return 0;

}

Image View Of Program

If you have any query comment below. Thanks

Easy & nice programme .

ReplyDeleteyour program are going to help me a lot .

thank you !

Welcome Mohit Khandewal

Deleteif i input 34

Deletethe factorial is 0

Then take long int inplace of only int

DeleteFactorial of 34 is returning 0 because you should use long long int data type for factorial.

DeletePrevious example produces the correct answer until 12! = 479001600.

Using long long int will work until 20.

Nice tutorial boss

Deletethank you so much

ReplyDeleteWelcom Kani.

Delete*******

ReplyDelete***

**

*

Nice program.

ReplyDeleteGood website, I had been searching for a good C++ website, now I think I got it

yes really

DeleteVery nice work... You are helping lots of students by sharing your knowledge with them!!

ReplyDeleteThanks Very Much Arundhati malik thakur. Keep Visiting.

DeleteHave A Look To Latest Programs

Find Palindrome Number in C++

*******

ReplyDelete*****

***

*

#include

#include

void main()

{

int a,b;

for(a=5;a>=1;a--)

{

for(b=1;b<=a;b++)

{

printf("*");

}

printf("\n");

}

getch();

}

can you provide me a program

DeleteQ: create a program on finding the roots of quadratic equation using for loop?

hello any one,,could u please help me with my situation..i need to make a coding base on formulae

ReplyDelete∑_(n=0)^m▒〖1/n!=1/0!+1/1!+1/2!+⋯….+1/n!〗....the question is,,ask user to enter the integer m,,then use the formulae,,i dont know

what is seekg(), seekp(), tellg(), tellp()???

ReplyDeleteThis comment has been removed by the author.

ReplyDeleteCan you help me to find a factorial of a number without using loop and if else

ReplyDeleteThis comment has been removed by the author.

ReplyDelete#include "stdafx.h"

ReplyDelete#include

using namespace std;

int factorial(int n)

{

cout<<"I am calculating: F("<>n;

int result = factorial(n);

cout<<result<<endl;

return 0;

}

can u give me a program on 0!=1 using for loop

Deletea linked queue program hw i can make function that deletes all my nodes

ReplyDeletea linked queue program hw i can make function that deletes all my nodes

ReplyDelete#include

ReplyDeleteint main()

{

int i, n, factorial=1;

printf("Enter Number to Find Factorial: ");

scanf("%d", &n);

for(i=1; i<=n; i++)

{

factorial=factorial*n--;

}

printf("Factorial: %d", factorial);

return 0;

}

Fahad use Code Mirror to show your code .. It will give your Code a better look and people can easily copy your code..

ReplyDeleteDone On New Posts. Thanks

Deletecan you give me a code using a loop please

ReplyDeleteYou Can Find Here. C++ Simple Examples

DeleteNice programs. Pls, I need a program to calculate zeno' s paradox.

ReplyDeleteplz find the factorial of 5 in do while loop

ReplyDeletenice

ReplyDeletethanks now it is easy to understand how factorial find

ReplyDeleteHow to write a program for the sum of this series

ReplyDeleteSum= 1/1! + 2/2! + 3/3! + 4/4! + 5/5! + 6/6!

Write a complete code to add first seven terms of the following series using nested loops.

Delete1/1! + 2/2! + 3/3! + …. 7/7!

If u have any idea about this please help me

Best Example (Y)

ReplyDeleteWrite a complete code to add first seven terms of the following series using nested loops.

ReplyDelete1/1! + 2/2! + 3/3! + …. 7/7!

Please help me fast

give me code for find fictorials of numbers 1 to 5 using for loop

ReplyDeletePlease help me out I can't find the answer of:

ReplyDelete2/2! - 3/3 + 4/4!

Please write complete code for this..

thank,s

ReplyDeletethank you so much for this tutorial

ReplyDeletethanks although

ReplyDeletevery nice

ReplyDelete1-(x^3/3!)+(x^5/5!)-(x^7/7!)...

ReplyDeletewap to input he values of x and n sum up n terms of the above series

the*

ReplyDeletewhy we should take factorial=1 when declaring the variable ?

ReplyDeletei did it this way because , our teacher told to include zero factorial in the program. please correct the program.

ReplyDelete#include

using namespace std;

int main()

{

int n,i=0,factorial ;

cout<<"Enter a number"<<endl;

cin << n ;

cout << " factorial = n! "<<endl;

for(i=0; i<=n;i++ )

{

if (i=0)

factorial n = 1;

else

factorial = factorial* i;

}

cout<<"factorial of the number is = " <<factorial<<endl;

return 0;

}

Is it possible to do this program using while or do while??

ReplyDeleteThanks very much

ReplyDeleteThanks very much

ReplyDeleteThis blog awesome and i learn a lot about programming from here.The best thing about this blog is that you doing from beginning to experts level.

ReplyDeleteLove from

good work

ReplyDeleteProgramming is combination of intelligent and creative work. Programmers can do anything with code. The entire Programming tutorials that you mention here on this blog are awesome. Beginners Heap also provides latest tutorials of Programming from beginning to advance level.

ReplyDeleteBe with us to learn programming in new and creative way.

typing using namespace std;

ReplyDeleteis giving me syntax error can any help me.

how to display maximum and minimum number in an array of 10 numbers

ReplyDeleteWhich function is used in c++ to clear screen.Like clrscr () in c

ReplyDeleteWill give bug if user enter 0

ReplyDeleteHOW TO WRITE SAME PROGRAM WITHOUT USING NAMESPACE STD ?????

ReplyDeleteIt's Good

ReplyDeleteIt's Good

ReplyDeleteHow to calculate sum of new natural numbers using "function" in C++ ?

ReplyDeleteHey can u provide me aa query

ReplyDeleteQ.Write a program that get 5 values in array from user and caculate the factorial of each value and store them in an other array

Plz provide me the following code

ReplyDeleteWrite a program that get 5 values from user in an array and calculte the factorial of each value and store them inan other array

Take a no froma a user and print its table.

ReplyDeleteTake a no from a user and print its fractional value.

ReplyDeletecan you do it using user-defined functions

ReplyDelete