Question #231917

An array is type of data structure that stores the elements in contiguous block of memory, create an array with name "list" and size of an array is N. your task is to print the array elements in an reverse order.

list=[1,2,3,4,5]

output 5,4,3,2,1

Note: use function concept to process the array elements and print it in the reverse order.

Reverse array has the following parameter

int list[n]

return int

Expert's answer



#include <stdio.h>


void reverseArray(){    
    int arr1[] = {11, 12, 13, 14, 15};     
    int len = sizeof(arr1)/sizeof(arr1[0]);    
        
    printf("Original: \n");    
    for (int i = 0; i < len; i++) {     
        printf("%d ", arr1[i]);     
    }      
    printf("\n");    
    printf("Reversed: \n");      
    for (int i = len-1; i >= 0; i--) {     
        printf("%d ", arr1[i]);     
    } 
}
int main()
{
    reverseArray();


    return 0;
}

LATEST TUTORIALS
APPROVED BY CLIENTS