kucheasysa

reverse of array

Jun 6th, 2023
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int size, i, temp;
  5.  
  6. printf("Enter the size of the array: ");
  7. scanf("%d", &size);
  8.  
  9. int arr[size];
  10.  
  11. printf("Enter the elements of the array:\n");
  12. for (i = 0; i < size; i++) {
  13. scanf("%d", &arr[i]);
  14. }
  15.  
  16. printf("Original array: ");
  17. for (i = 0; i < size; i++) {
  18. printf("%d ", arr[i]);
  19. }
  20. printf("\n");
  21.  
  22. // Reversing the array
  23. for (i = 0; i < size / 2; i++) {
  24. temp = arr[i];
  25. arr[i] = arr[size - 1 - i];
  26. arr[size - 1 - i] = temp;
  27. }
  28.  
  29. printf("Reversed array: ");
  30. for (i = 0; i < size; i++) {
  31. printf("%d ", arr[i]);
  32. }
  33. printf("\n");
  34.  
  35. return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment