Write a program to reverse an array.
Example:
Input: arr[]={2,1,4,3,5}
Output: Rverse array is
5 3 4 1 2
C Program
#include <stdio.h>int main(){int arr[] = {2, 1, 4, 3, 5};int n = sizeof(arr) / sizeof(arr[0]);for (int i = 0; i < n / 2; i++){int temp = arr[i];arr[i] = arr[n - i - 1];arr[n - i - 1] = temp;}printf("Rverse array is\n");for (int i = 0; i < n; i++){printf("%d ", arr[i]);}return 0;}
No comments:
Post a Comment