The amount of square numbers less than a number (n) is no greater than the sqrt(n). So create an array of size (int)sqrt((double)n);. This array is to hold all of the square numbers.
It is then your job to go through every combination of this array and see if the sums equal n. If they do, print the line.
If you haven't learned about making a dynamically allocated array, perhaps just make a array that is large enough that your teacher says "okay". Perhaps use a vector instead of array. Such things depend on how much you have learned in class.
Outputting an array can be done with a simple for loop where you compare the variable in the initialization expression to the max size of the array then use that to cout each element of the array. While that sounds confusing it is simple once you see it in code:
1 2 3 4
for (int i = 0; i < arraysize; i++)
{
cout << array[i];
}
Obviously you have to replace "arraysize" and "array" with whatever you used to initially create your array. In the example you just gave, that would look like:
Also, I just remembered another for loop that was added with the new C++11 standard, so it might not be supported by your compiler. The range-based for loop. It would look like this in your code:
1 2
for (int x : a)
std::cout << x
Basically, int x represents the first element of the array a. It then outputs it, and will increment x to the 2nd element and so on until the end of the array is reached.
You can edit the posts to alert to updated code (though I dont see it nessescary) but deleting will make it harder for others to solve a similar issue.