Array Fill (what's wrong with this code)

Write a program that reads a number T and fill a vector N[1000] with the numbers from 0 to T-1 repeated times, like as the example below.

Input

The input contains an integer number T (2 ≤ T ≤ 50).

Output

For each position of the array N, print "N[i] = x", where i is the array position and x is the number stored in that position.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #include <iostream>

using namespace std;

int main()
{
   int N[1000] , T;

   cin>>T;

  for(int i=0;i<1000;i++)
   {
       for(int j=0;j<T;j++)
       {
           cout<<"N["<<j<<"] = "<<j<<endl;

       }
   }
    return 0;
}
YOu forgor to fill your N array.
you're supposed to use a vector

http://www.cplusplus.com/reference/vector/vector/?kw=vector

with each increase of j, increase i too... and also print i

1
2
3
4
5
6
7
8
9
for(int i=0; i<1000; ++i)
{
       for(int j=0; j < T; ++j, ++i)
       {
           // fill the vector on ith position with j's value here
           cout<<"N[ " << i << "] = " << j <<endl; // do not print j, print value from vector instead
           if(i == 999) break;  // have to check whether i is not 999 already 
       }
}
Last edited on
Topic archived. No new replies allowed.