Advertisement
jpenguin

reverse_array.c

Feb 22nd, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. #include<stdio.h>
  2. #define length 9
  3. //https://www.studytonight.com/c/datatype-in-c.php/
  4. //http://www.cplusplus.com/reference/cstdio/printf/
  5. int main()
  6. {
  7.     short unsigned int num[length];
  8.  
  9.     for(int x=0; x<length;x++)  //Fill the array with numbers 0-length
  10.         num[x]=x;
  11.     for(int x=0; x<length;x++)  //Print initial array
  12.         printf("%hu\n", num[x]);
  13.     printf("\nReversing...\n\n");
  14.     for(int x=0, y; x<length/2;x++)
  15.     {
  16.         y=num[x];
  17.         num[x]=num[length-x-1];
  18.         num[length-x-1]=y;
  19.     }
  20.     for(int x=0; x<length;x++)  //print reversed array
  21.         printf("%hu\n", num[x]);
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement