# array definitions

• 11-08-2002
correlcj
array definitions
greetings,

i am to write a definition and statement to construct a given array.

1. an array whose indices are the integers from 0 thru 99 and in which the value stored in each array element is the same as the indices in reverse order.

code:--------------------------------------------------------------------------------
int array[100];
for(int i = 0; i < 100; i--)
array[i] = [i];
--------------------------------------------------------------------------------
• 11-08-2002
correlcj
YES!! it is!
Thankls but i corrected it

Code:

``` int array[100]; for(int i = 0; i < 100; i--) array[i] = [i];```
Thanks anyways for ALL your help.

:D
• 11-08-2002
Will
Re: array definitions
yeah, that's an infinite loop. it should be something like

Code:

```#include <iostream> using namespace std; int main() {         int array[100];         int garbage = 0; //just used to pause execution. you can take this out if you want.         int j = 0;         for (int i = 99; i > 0; i--)         {                 j = (100 - i);                 array[j] = i;                 cout<< "Array["<<j<<"] is "<<array[j] <<endl;;                 if (i%20 == 0)                         cin>>garbage;         }         return 0; }```
EDIT: unless, of course, I misunderstood the question. which is possible.
• 11-08-2002
correlcj
Quote:

unless, of course, I misunderstood the question. which is possible
NOPE! U got it! Thanks Will!
cj
• 11-09-2002
Absy
array
Can I write in this way:

#include <iostream>
using namespace std;

int main()

{
int array[100];
int garbage = 0;
int j = 0;

for (int i = 0; i < 99; i++)
{
j = (100 - i);
array[i] = j;
cout<< "Array["<<i<<"] is
" << array[j]<<endl;

if (i%20 == 0)
cin>>garbage;
}
return 0;
}
• 11-09-2002
ammar
Correct me if I'm wrong.
Yeah this willl loop until the value of i becomes geater than what an integer can take, then you will get an error.
• 11-09-2002
Absy
I thought the loop will stop when i is less than 99
• 11-09-2002
```#include <iostream> using namespace std; int main() {   int array[100];   int garbage = 0;   int j = 0;   for (int i = 0; i < 100; i++)  {     j = (100 - i); //j will range from 100 to 1 as i will be 99 at max     array[i] = j;     cout << "Array[" <<  i << "] is" << array[j] << endl; //always put spaces between operators, etc.  It makes it much easier to read   if (i%20 == 0)//nice trick to freeze the screen every 20 lines   //except the first time, when it will be 21 lines.    cin >> garbage;  }  return 0; }```