Write C code to reverse the contents of the array.For example, [1,2,3,4,5] should become [5,4,3,2,1] : -


Ans :

#include<stdio.h>
 
int main()
{
    int arr[20], limit, i;
    printf("Enter Limit:\t");
    scanf("%d", &limit);
    printf("\nEnter %d Elements in 1-Dimensional Array\n", limit);
    for(i = 0; i < limit; i++)
    {
        scanf("%d", &arr[i]);
    }
    printf("\nArray Elements\n");
    for(i = 0; i < limit; i++)
    {
        printf("%d\t", arr[i]);
    }   
    printf("\nReverse of Array\n");
    for(i = limit - 1; i >= 0; i--)
    {
        printf("%d\t", arr[i]);
    }
    printf("\n");
    return 0;
}

Comments

Popular posts from this blog