## Factorial codes in C++ program

Asked By 0 points N/A Posted on -

What codes I should use to have an output that asks a user a number and prints its factorial?

SHARE
Answered By 0 points N/A #102848

## Factorial codes in C++ program

Hi Archie using C++ it is very easy to perform operation of factorial and also remember that values can be given both statistically and dynamically at runtime.

The syntax is different from one language to another language but the logic will be same in any language so first try to note the logic and then we can implement in our program by syntax easily.

As you know that execution starts from main() you have to insert the logic of the function in the main method only otherwise you will not get the correct output.

Logic is nothing but as follows…

for(f=1;f<=4;f++)

factorial=factorial*f;

here factorial and f are the variables where as factorial variable gets the output by using printf command.

Hence then you can get the exact output of the value which you give by implementing logic in the main method and compile and run it without errors.

Thank You.

Answered By 0 points N/A #102849

## Factorial codes in C++ program

Hi there ,

It seems you need the code for finding a factorial.

I hope only the mathematical logical parts are confusion for you and i hope you are thorough with the C++ basics.

I am giving you the codes of the formulated algorithm , These can be done with other looping statements like for loop and all , I suggest this way.

Here are the codes :-

//Write the codes to get the limit of the factorial to be produced into the "lim" varaible.

//then

long int i=0,fact=1;

i=lim;

while(lim!=0)

{

fact = fact * lim;

— lim;

}

// Now type the code to print the variable "fact" , and that is your factorial of the given limit.

I hope you are clear and your problem is solved

good luck.

Answered By 0 points N/A #102850

## Factorial codes in C++ program

Yes very clear and got all your steps. Thanks  a lot for the help Lesten. Keep it up! Hope you continouosly help others just what you did now.. thanks