Display a factorial sequence as a string
// here is my code to find a factorial of a number:
int get_factorial(int num)
{
auto sum = 1;
while(num > 0)
{
sum = sum * num;
num--;
}
return sum;
}
// this works to give me the factorial but my assignment wants me to return a string. so if my parameter is 5, instead of returning 120 like my code does currently I need it to return a string that says "1x2x3x4x5 = 120". "5x4x3x2x1 = 120" should also work.
I'm unsure where to start. I thought maybe creating a string and appending each sum as it goes through the loop but I don't know how to do that.
Comments
Post a Comment