+ 8
How to store the numbers between 100 and 200 in an array having size of 100 in C++?
8 Antworten
+ 2
Arrays with sequential numbers ....100 -> 200...(lower bound and upper bound included)....bare in mind the array now has a length of 101 so adjust/amend as you need:-
#include <iostream>
#include <numeric> // iota()
using namespace std;
int main()
{
int arrayA[101];
iota(arrayA,arrayA+101, 100);
for(unsigned int i = 0; i < 101;i++)
cout << arrayA[i] << ' ';
cout << endl;
//#####################
int arrayB[101];
for(unsigned int i = 0; i < 101;i++)
arrayB[i] = i+100;
for(unsigned int i = 0; i < 101;i++)
cout << arrayB[i] << ' ';
return 0;
}
+ 7
rodwynnejones Sorry, didn't got that, me a very beginner, pls explain with some examples, anyway thanks...
+ 7
rodwynnejones sequential one
+ 6
https://code.sololearn.com/c49M8hw2PgS4/?ref=app
Finally got it. I think there are several methods for this, but i know this only. I tried to solve this with nested loops, but can't solve. I solved this by defining some seperate functions. So those who knows the alternative (easy) ways to solve this problem, pls share your ideas. Especially who knows solving this problem with the nested loop.
+ 6
rodwynnejones Thanks ❤️
+ 4
You can quickly assign sequential numbers to an array using 'iota' from the 'numeric' header file...or...use a simple 'for loop' with 'rand' from 'cstdlib' or.... have a look at the 'random' header file.
+ 3
If you want to sort 100 given numbers (between 100 and 200) you can do it with a while loop that inside will test wether the first number in your array is greater than the next and so on. There are many ways to do it, but perhaps that's an easy one.
+ 2
Are you looking to make a array with 100 random numbers between 100 and 200 (inclusive) or sequential numbers e.g 100, 101, 102, 103, 104 .....--> 200?