0

How would I go about writing the loop for displaying the index 0,1,2 ... 9 for an array with 10 elements ?

here is the code; I know i need to use a for loop, but where and how do i write it ? i tried :

for(int index=0;index<20;index++)
cout index;

int main()
{
   const int ARRAY_SIZE = 10;	  // Array size
   int numbers[ARRAY_SIZE]; {10,20,30,40,50,60,70,80,90,100}
   int count;                               // Loop counter variable
   int index;
    	
   for(count=0;count < ARRAY_SIZE;count++)
   cout >>numbers[count];                 // writes the values in the elements.

    cout<<"\t\t"<<setw(10)<<"Index"<<setw(20)<<"Content\n\n"; 
  
   for(count=0;count < ARRAY_SIZE;count++)
   
   for( index=0;index<20;index++) 

   cout<<"\t\t"<<setw(10)<<index<<setw(16)<<numbers[count] <<"\n\n";
     
    return 0;
}

Thank you.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by Ancient Dragon
0

>> int numbers[ARRAY_SIZE]; {10,20,30,40,50,60,70,80,90,100}

That is incorrect. Here is what you want int numbers[ARRAY_SIZE] = {10,20,30,40,50,60,70,80,90,100}; The index number is nothing more than the loop counter. Therefore you can delete the line for( index=0;index<20;index++) then cout the value of count instead of index.

Edited by Ancient Dragon: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.