In this blog, you will learn how to reverse an array in C programming.
Introduction
- In this blog, i am going to explain how to reverse an array.
Software Requirements
Programming
- #include < stdio.h >
- int main()
- {
- int n, c, d, a[100], b[100];
- printf("Enter the number of elements in array\n");
- scanf("%d", & n);
- printf("Enter the array elements\n");
- for (c = 0; c < n; c++) scanf("%d", & a[c]);
- for (c = n - 1, d = 0; c >= 0; c--, d++) b[d] = a[c];
- for (c = 0; c < n; c++) a[c] = b[c];
- printf("Reverse array is\n");
- for (c = 0; c < n; c++) printf("%d\n", a[c]);
- return 0;
- }
Explanation
- In the programming given above, it is easily understood that the array is reversed and the output can be printed.
Output