arrays c++

I want to store numbers from 200 to 400 in array can someone help me how it is done?
1. Construct a sequence container (a std::vector is IMO a good choice since it will use the heap for storage) that can contain 201 elements.
https://en.cppreference.com/w/cpp/container/vector

2. Using std::iota on the container with a starting value of 200 will fill the elements with the increasing value 200 - 400.
https://en.cppreference.com/w/cpp/algorithm/iota
1
2
3
4
5
6
7
8
9
10
#include <array>
#include <numeric>

int main() 
{
  int constexpr upper_bound = 400 + 1;
  int constexpr lower_bound = 200;
  std::array<int, upper_bound - lower_bound> xs; 
  std::iota(std::begin(xs), std::end(xs), lower_bound)
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

const int how_many =  400 - 200 + 1;

int main()
{
    int store[how_many];
    
    for(int i = 0; i < how_many; i++)
    {
        store[i] = 200 + i;
    }
    
    for(int i = 0; i < how_many; i++)
    {
        cout << i << '\t' << store[i] << endl;
    }
    
    return 0;
}
Topic archived. No new replies allowed.