1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

1-D array

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

  1. jack999

    jack999 New Member

    Joined:
    Apr 21, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    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

    Joined:
    May 9, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    0
    Show your efforts first.
     
  4. coderzone

    coderzone Super Moderator

    Joined:
    Jul 25, 2004
    Messages:
    734
    Likes Received:
    37
    Trophy Points:
    0
    Exactly.
     

Share This Page