Implement a function in C that takes an array of integers,%26amp; 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
__,_._,___
Need help with implementing C that takes an array of integers,%26amp; and reverses the order of items in the array?
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%26gt;=0;i--){
modarray[j] = origarray[i];
j++;
}
Reply:Well now you have the reverseArray function. Does it all work now????
;-)
Reply:Use a for loop
swap a[i] with a[n-i-1]
a[0] a[5-0-1]
tomato plants
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment