q2. wap in c to input 5 numbers in an array and display in reverse order.

Code Explanation:

Here is a C program that inputs 5 numbers into an array and displays them in reverse order:

#include <stdio.h>

int main() {
    int arr[5];
    int i;

    // Input 5 numbers into the array
    printf("Enter 5 numbers:\n");
    for (i = 0; i < 5; i++) {
        scanf("%d", &arr[i]);
    }

    // Display the numbers in reverse order
    printf("Numbers in reverse order:\n");
    for (i = 4; i >= 0; i--) {
        printf("%d\n", arr[i]);
    }

    return 0;
}

Explanation of each step:

  1. Declare an integer array arr of size 5 to store the numbers.
  2. Declare an integer variable i for looping.
  3. Prompt the user to enter 5 numbers using printf.
  4. Use a for loop to input the numbers into the array using scanf. The loop runs from i = 0 to i < 5, incrementing i by 1 in each iteration.
  5. After the loop, display the numbers in reverse order using another for loop. The loop runs from i = 4 to i >= 0, decrementing i by 1 in each iteration.
  6. Inside the loop, use printf to display each number on a new line.
  7. Finally, return 0 to indicate successful execution of the program.

This program uses a simple approach to input 5 numbers into an array and display them in reverse order.