>what does it this mean Initialize the array so that the first 25
>components are equal to the square of the index variable ?
I would assume something like this:
for ( int i = 0; i < 25; i++ )
alpha[i] = i * i;
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
I thought this was initialization:
int num[] = {1, 2, 3, 4};
and this:
int num[4];
for(int i = 0; i < 4; i++i)
num[i] = i;
represented serial assignment.
Furthermore I think that either the instructor, the OP, or I (and I don't think it's me this time) don't know the difference between iniatialization of the elements of an array and assignment to the elements of an array and use the two concepts interchangeably, as they can end up with the same result.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
before every thing thank you for helping , and Im asking if these answer is right :
# include <iostream>
using namespace std ;
int main ()
{
int alpha[50];
for (int i=0;i<25;i++)
{
alpha[i]=i*i;
cout<<alpha[i]<<" ";
for(i=25;i<50;i++)
{
alpha[i]=3*i;
cout<<alpha[i]<<" ";
}
return 0
}
also I have question how can I print 10 elements per line if I had 2 loop
and thank you very much ,
You're on the right track. Another solution would be to use only one for loop and use an if else test condition to test for the first 25, do whatever...
As regards printing 10 per line, you could make use of the % modulus operator to determine whether a newline should be printed if (i % 10 == 0) .
I hope this is of value.
superjacent
Junior Poster in Training
66 posts since Nov 2007
Reputation Points: 11
Solved Threads: 3
This works if you don't mind the newline right from the get go.
if (i % 10 == 0)
cout << endl;
cout << alpha[i] << "\t";
superjacent
Junior Poster in Training
66 posts since Nov 2007
Reputation Points: 11
Solved Threads: 3
this is my answer ; is it right ?
I'd guess that you should be able to determine if it's right or not and I'm suspecting you're guessing it's not.
I'd suggest removing the cout statements from the for loops of the assignment statements, they just print 25 across the line, which is not what you want.
I removed those cout statements and your code is nearly there. The first line only prints 9 numbers, the rest print 10.
superjacent
Junior Poster in Training
66 posts since Nov 2007
Reputation Points: 11
Solved Threads: 3