1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

1-D array

Discussion in 'C' started by jack999, May 12, 2006.

  1. jack999

    jack999 New 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????
     
  2. shabbir

    shabbir Administrator Staff Member

    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
     
  3. Aztec

    Aztec New Member

    Show your efforts first.
     
  4. coderzone

    coderzone Super Moderator

    Exactly.
     

Share This Page