Question #247115

1 Write a function in C++ to find the factorial of a number (using while loop).


Expert's answer

int factorial(int n) {
    int x = 1;
    int i = 2;
    while (i <= n) {
        x *= i;
        i++;
    }
    return x;
}

Sorry, my bad, mistake choosing loop)


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS