<<< Reverse Array | Logical Flow of Code (LFoC)

for(i=0; i<n; i++)

{

    scanf("%d", &a[i]);

}

for(i=n-1; i>=0; i--)

{

    printf("%d ", a[i]);

}




Input: 5

Input: 10 20 30 40 50

Output: 50 40 30 20 10

#AbdurRahimRatulAliKhan #CodeDescription #ReverseArray


This code snippet demonstrates the reversal of an array of integers in the programming language. The array size, 'n', is taken as input from the user, followed by the array elements themselves. Then, the array is printed in reverse order.

1. First, the variable 'i' is initialized to 0.

2. The 'for' loop takes 'n' elements of the array 'a' as input using the 'scanf' function, one element at a time.

3. Next, another 'for' loop is used to print the elements of the array 'a' in reverse order. The variable 'i' is initialized to 'n-1', and the loop continues until 'i' becomes less than or equal to 0.

4. Inside the loop, 'printf' is used to display the elements in reverse order, separated by a space.

Input: The code expects an integer 'n' as the number of elements in the array. This is followed by 'n' integers representing the array elements.

Output: The code outputs the reversed array elements in a single line, separated by spaces.


#Programming #Array #Reversal #CodeSnippet