Thread: arrays proplem
View Single Post
Join Date: Nov 2007
Posts: 66
Reputation: superjacent is an unknown quantity at this point 
Solved Threads: 3
superjacent's Avatar
superjacent superjacent is offline Offline
Junior Poster in Training

Re: arrays proplem

 
0
  #7
Dec 29th, 2007
Originally Posted by bis student View Post
before every thing thank you for helping , and Im asking if these answer is right :
  1. # include <iostream>
  2. using namespace std ;
  3. int main ()
  4. {
  5. int alpha[50];
  6. for (int i=0;i<25;i++)
  7. {
  8. alpha[i]=i*i;
  9. cout<<alpha[i]<<" ";
  10. for(i=25;i<50;i++)
  11. {
  12. alpha[i]=3*i;
  13. cout<<alpha[i]<<" ";
  14. }
  15. return 0
  16. }
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.
Reply With Quote