This program serves as a practical example for beginners to understand array manipulation, function usage, and basic input/output operations in the C programming language. It also introduces concepts like function prototypes and error handling.

The main objective of the program is to read integers into an array, print the array, reverse its order, and print the reversed array.

Note: You can read more about Arrays in this article: Arrays in C

Main Functions of the Program

Key Features:

  1. intSwap Function:
    • This function swaps the values of two integer variables, facilitating the reversal of array elements.
  2. printIntArray Function:
    • Prints the elements of an array in a user-friendly format, with a specified number of elements per line.
  3. getIntArray Function:
    • Reads integers from the user until a sentinel value (in this case, 0) is entered or the array is full.
    • Provides basic input validation and handles the array size limit.
  4. reverseIntArray Function:
    • Reverses the order of the first n elements in the array by using the intSwap function.

Source Code of the C Program

Output of this C program is:

Enter integer [0 to terminate] : 5
Enter integer [0 to terminate] : 4
Enter integer [0 to terminate] : 3
Enter integer [0 to terminate] : 2
Enter integer [0 to terminate] : 1
Enter integer [0 to terminate] : 0
The array was:
5 4 3 2 1

After reversing, it is:
1 2 3 4 5