1. ## C++ program question

1.
int array_a[5] = { 3, -5, 6, -2, 1}
write a program using a loop statement to double the value of every time in array_a and then display only negative items in the array. use the statement cout for output.

2.
An array with a list of numbers {89, 68, 5, 12} is to be sorted in ascending order using the selection sort algorithm. There should be 3 rounds of elements swapping before the list is sorted. Show the array contents after each round of swapping in sequence.

can anybody help with me with these questions?

2. The way homework/assignments work here is that you show that you are working on it, then we help you get to a solution, not "You post the assignment, we solve it for you".

--
Mats

3. We can certainly help you with problems you come across in the process when you get underway, however there's nothing for us to help you with yet because you don't appear to have started.

4. Or maybe rather... you haven't asked any really specific questions. Sometimes one might have trouble getting started. Then you could ask for some advice from whatever you might have pondered about yourself.
But do try getting started and asking when/if you get stuck. That's the best way.

5. here is specofoc questions..
for the q1.
for doubleing...
Code:
```const int arraysize = 5;
int array_a[ arraysize] = { 3, -5, 6, -2, 1};
for ( int k =0; k < arraysize; k++)
[k] *= 2;```
then, how can i display the negative numbers only?

for q2
is the each round of array contents :
1st : 68,89,5,2
2nd : 5,68,89,2
3rd: 2,5,68,89

6. That's not quite right. That can't be your real code, can it?
But as for only negative numbers, you only need to loop through your array and check if the number is negative, THEN print it, otherwise don't.
You shouldn't have much problem with that.

7. For the second question, consider using pointer notation via selection sort. I do not know if you have covered pointers yet, but somthing like this:

Code:
```void swapEelements ( int *pElement1, int *pElement2 )
{
int hold = *pElement1;

*pEelement1 = *pElement2;

*pEelement2 = hold;
}```
Of course, there is a load more to this method, but that sort of algorithm is quite efficient, although you do have to pass each element to the function to swap it, and this could be a little complex. Its just an idea.

8. For the second question, consider using pointer notation via selection sort. I do not know if you have covered pointers yet, but somthing like this:
Or rather, pass by reference.

9. Originally Posted by laserlight
Or rather, pass by reference.
thanks..i get the q2 by selection sort of pass by reference usign pointers