954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

C++ recursive function

I have a recursive function squares that receives a positive integer n and prints out the first n perfect squares in descending order. Can anyone tell me if this is correct and if not please help.

squares(int n)
{
if( n== 1 )
return 1;

else
return squares ) n * n );
}

buddy1
Newbie Poster
17 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 
void squares(int n)
{
    if( n== 1 ) 
        cout << 1 ;
    else
    {
         cout << n*n << " " ;//swap lines 7 & 8 for ascending order
         squares ( n- 1 );
    }
}
Prabakar
Posting Whiz
342 posts since May 2008
Reputation Points: 94
Solved Threads: 33
 

Thanks for the help

buddy1
Newbie Poster
17 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You