Question:
need help with implementing C that takes an array of integers,& and reverses the order of items in the array?
hisluv
2007-09-13 06:58:03 UTC
Implement a function in C that takes an array of integers,& and reverses the order of items in the array?
The function you implement must have the following form:
void reverse_order(int array[], int n)
{
/* your code goes here: re-order the n items in the array so that the
first one becomes the last
* * and the last one first.
*/
}
You should then implement a main() function which reads in a set of integers into an array,
reverses the order of the number (using the function you have just defined) and prints them out
again.
For example, when complete and compiled, you should be able to run your program, and enter
the numbers:
2 4 5 11 23 1 4
then program will then print out:
4 1 23 11 5 4 2
__,_._,___
Three answers:
anonymous
2007-09-13 07:29:34 UTC
Use a for loop

swap a[i] with a[n-i-1]



a[0] a[5-0-1]
ko_cjun
2007-09-13 14:25:46 UTC
simple in the reverse function just make another array that will copy the orignal array backwards

j=0;

for(int i=sizeof(array)-1;i>=0;i--){

modarray[j] = origarray[i];

j++;

}
?
2007-09-15 02:03:24 UTC
Well now you have the reverseArray function. Does it all work now????

;-)


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...