Advertisement
Guest User

Challenge #14 [easy]

a guest
Feb 24th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main(const int argc, const char * argv[]) {
  6.  
  7.         int b = atoi(argv[1]);
  8.  
  9.         int list[] = {1, 2, 3, 4, 5, 6};
  10.         int listSize = sizeof list / sizeof (int);
  11.         int origList[listSize];
  12.  
  13.         memcpy(origList, list, sizeof(int[listSize]));
  14.         int blocks = listSize/b;
  15.  
  16.         int i, x;
  17.         for (i = 0; i < blocks; i++) {
  18.                 for (x = 0; x < b; x++) {
  19.                         if (!x) list[b*i+x] = origList[b*(i+1)-x-1];
  20.                         else list[b*i+x] = origList[b*(i+1)-x-1];
  21.                 }
  22.         }
  23.  
  24.         int z;
  25.         for (z = 0; z < listSize; z++) printf("%d\t",origList[z]);
  26.         puts("\n");
  27.         for (z = 0; z < listSize; z++) printf("%d\t",list[z]);
  28.         puts("\n");
  29.  
  30.         return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement