-3

It's supposed to be N={0,1,2...N} N is entered by the user. If N is 6 then N={0,1...5} The numbers from 0 to N should fill the array. We haven't studied vectors yet so that's not an option.

V.R
  • 1
  • Use `std::cin` to read `N`, then use `new[]` to allocate an array of `N` elements, then use a loop from `0` to `N-1` inclusive to fill the array (as I assume you haven't studied standard library algorithms either, like `std::fill()`, `std::generate_n()`, etc). Have you tried that yet? Dynamic arrays should be covered by any decent C++ tutorial/book. – Remy Lebeau Jan 12 '19 at 06:55
  • Then you will have to use a dynamic array, this will help you [How to create a dynamic array](https://stackoverflow.com/a/4029897/7631183) – Wanderer Jan 12 '19 at 07:04
  • 1
    Don't expect us to do your homework. What have you tried so far? Show us your code please. – Sceptical Jule Jan 12 '19 at 07:28
  • I tried a few different ones but nothing worked. I tried searching what to use but everything got confusing. Most of the example codes contain elements we haven't studied – V.R Jan 12 '19 at 07:32
  • Do the "elements" you *have* studied include integral types, reading input, dynamic allocation/deallocation using operators `new` and `delete`, and loops? If so, you have studied all the necessary ingredients to solve your homework problem on your own. – Peter Jan 12 '19 at 07:44

1 Answers1

1

First of all, allocate in memory an array of size n+1

int *arr= new int[n+1];

Iterate over this array, and assign the corresponding values

for(int i=0; i<n+1; ++i)
  arr[i] = i;
Gaurav Pant
  • 724
  • 7
  • 22
  • It is not too helpful just to provide the code without any explanation. OP seems to be a beginner, risk is that she/he will just copy/paste the code without learning anything... – Aconcagua Jan 12 '19 at 07:22
  • Most coding conventions mandate variables being named in camel case, starting with small letter. `N` would violate this convention, you should prefer `n` instead. – Aconcagua Jan 12 '19 at 07:25