1-D array

jack999's Avatar
Newbie Member
Write a C-Program that swaps the elements of 1-D array (10 elements) :
Example:
If the given array is:
5 8 9 2 3 1 11 17 43 6
The new array will be:
6 43 17 11 1 3 2 9 8 5
Your program should consist of the following functions:
1. Function READ to read the elements of the array
2. Function Display to print the elements of the new array
3. Function SWAP to swap the elements of the array
4. main function to call the previous functions
Note: in swap function, do not use an intermediate array for swapping, i.e. do not
declare a new array and fill it with the elements of the original array starting from the
last element. The swap operation should be done on one array

The size of array must be N (Entered by user)



my question is how can i swap the elements of the array????
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Quote:
Originally Posted by jack999
my question is how can i swap the elements of the array????
By taking a temp variable and then interchanging the values from one to the other.

temp = Arr[n];
Arr[n] = Arr[m];
Arr[m] = temp;

Thanks
Shabbir
Aztec's Avatar, Join Date: May 2006
Contributor
Show your efforts first.
coderzone's Avatar, Join Date: Jul 2004
Team Leader
Quote:
Originally Posted by Aztec
Show your efforts first.
Exactly.