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.

>> 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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.