Multiplying sequence. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Multiplying sequence.

I'm using C++ for this, i'm wanting to be able to input a number, say 5,and output the answer of 5*4*3*2*1. how would I go about doing this?

13th Feb 2018, 4:24 PM
Koty Wilkinson
Koty Wilkinson - avatar
2 Answers
+ 1
a general approach... not in any specific language a=5 for i from 5 to 1 a=a*i or a=5 for i from 1 to 5 a=a*i or function factorial(argument): if argument==1 then return 1 else return argument*factorial(argument-1) //calling the func. factorial(5)
13th Feb 2018, 6:01 PM
sayan chandra
sayan chandra - avatar
0
Thank you!
13th Feb 2018, 6:02 PM
Koty Wilkinson
Koty Wilkinson - avatar