[try Beta version]
Not logged in

 
if array is more than 10

Mar 19, 2017 at 11:35pm
lets say the size of the array is 50
i just want to print the last 10
40-49

Mar 20, 2017 at 12:31am
You cycle through an array with a for loop.

1
2
3
4
for(int i = 0; i < sizeOfArray; i++)
{
     cout << arrayName[i] << endl;
}


This cycle through the entire array from 0 (because thats what i is) to the size of the array (in this case you said 50)

So lets say we changed i to lets say 40? What do you think will happen?
Mar 20, 2017 at 12:47am
1
2
3
4
5
6
7
8
9
10
11
        cout << "Enter a max number between 2-5000 to find all primes:  ";
	cin >> max;
	if (max > 5000)
	{
		cout << "Too big, enter a number lower than 5000: ";
		cin >> max;
	}
	if (max > 100)
	{
		primearr[(max-1)-100] = primearr[max]; // to print last 100 elements
	} // is this a good initialization? 
Mar 20, 2017 at 1:19am
Not sure what you're trying to do here. What exactly are you trying to initialize in Line 10?

primearr[(max-1)-100] = primearr[max];
Topic archived. No new replies allowed.