The integer variables first and last have been declared and assigned values (with last >= first). Allocate an integer array that can hold the squares of the numbers between first and last (inclusively), assign the resulting pointer to the variable squares (which you must declare), and initialize the array to the squares of the numbers from first to last (in that order).
.
.
Click on the title for the solution
.
.
int *squares = new int [last+1-first];
for (int i=first; i<=last; i++)
{
squares[i-first]=i*i;
}
.
Click on the title for the solution
.
.
This is the answer:
:
int *squares = new int [last+1-first];
for (int i=first; i<=last; i++)
{
squares[i-first]=i*i;
}
Comments
Post a Comment