Advertisement
neversmile

reverse an array

Jun 20th, 2013
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int n, c, d, a[100], b[100];
  6.  
  7. printf("Enter the number of elements in array\n");
  8. scanf("%d", &n);
  9.  
  10. printf("Enter the array elements\n");
  11.  
  12. for (c = 0; c < n ; c++)
  13. scanf("%d", &a[c]);
  14.  
  15. /*
  16. * Copying elements into array b starting from end of array a
  17. */
  18.  
  19. for (c = n - 1, d = 0; c >= 0; c--, d++)
  20. b[d] = a[c];
  21.  
  22. /*
  23. * Copying reversed array into original.
  24. * Here we are modifying original array, this is optional.
  25. */
  26.  
  27. for (c = 0; c < n; c++)
  28. a[c] = b[c];
  29.  
  30. printf("Reverse array is\n");
  31.  
  32. for (c = 0; c < n; c++)
  33. printf("%d\n", a[c]);
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement