Value swaping/transposing in an array loop

This is a discussion on Value swaping/transposing in an array loop within the C Programming forums, part of the General Programming Boards category; AWESOME!!!!!! thank for all the tips and advice I got it going I really appreciate giving me advice and not ...

  1. #16
    Registered User
    Join Date
    Feb 2013
    Posts
    41
    AWESOME!!!!!! thank for all the tips and advice I got it going I really appreciate giving me advice and not just the straight out code of how it would work. Thanks agian
    Code:
    int i = 0;
     int temp = a[size -1];
     printf("Now the array is \n");
     for (i = 0; i <= size -1; i++)
     {
      
      
      
      a[i] = i -1;
      if(a[i] == -1)
      {
       a[i] = temp;
      }
      printf("%3d", a[i]);
      
      
     }
     
     printf("\n");
    





  2. #17
    Registered User
    Join Date
    Apr 2013
    Posts
    1,255
    If you're trying to rotate the array instead of just assigning new values it would look like:

    Code:
    int i = 0;
        int temp = a[size-1];
        for (i = size-1; i > 0; i--)
            a[i] = a[i-1];
        a[0] = temp;
    }

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Transposing a matrix made from a 1d array
    By brown in forum C Programming
    Replies: 4
    Last Post: 10-06-2009, 02:05 PM
  2. Swaping the variables
    By rits in forum C Programming
    Replies: 7
    Last Post: 03-10-2009, 04:40 PM
  3. swaping characters
    By tikelele in forum C Programming
    Replies: 12
    Last Post: 11-06-2007, 02:37 PM
  4. swaping numbers
    By bj31t in forum C++ Programming
    Replies: 14
    Last Post: 03-30-2004, 07:52 AM
  5. swaping using pointers
    By coloughl in forum C Programming
    Replies: 2
    Last Post: 05-17-2002, 08:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21