Returning Recursive function

pls, i just need help making this a returning function instead of void -> int and retunr the squared.

1
2
3
4
5
6
7
8
9

void squared(int sq)
{
    if(sq != 1)
    squared(sq - 1); //recursive call for squared integers from 1 to integer
    cout << setw(3) << sq << setw(12) << sq * sq << endl;

}
Last edited on
return sq*sq would return you the square of the number. What are you trying to achieve?
Topic archived. No new replies allowed.