Home / Programs / C Program to Reversing an Array Elements in C Programming
🚀 Programming Example

C Program to Reversing an Array Elements in C Programming

👁 1,315 Views
💻 Practical Program
📘 Step Learning
C Program to Reversing Array Elements in C Programming

💻 Program Code

/* 
C Program to Reversing an Array Elements in C Programming
Author: Atnyla Developer

*/


#include<stdio.h>
 
int main() {
   int arr[30], i, j, num, temp;
 
   printf("\nEnter no of elements : ");
   scanf("%d", &num);
 
   //Read elements in an array
   for (i = 0; i < num; i++) {
      scanf("%d", &arr[i]);
   }
 
   j = i - 1;   // j will Point to last Element
   i = 0;       // i will be pointing to first element
 
   while (i < j) {
      temp = arr[i];
      arr[i] = arr[j];
      arr[j] = temp;
      i++;             // increment i
      j--;          // decrement j
   }
 
   //Print out the Result of Insertion
   printf("\nResult after reversal : ");
   for (i = 0; i < num; i++) {
      printf("%d \t", arr[i]);
   }
 
   return (0);
}
                        

🖥 Program Output


Enter no of elements : 5
5
4
3
2
1

Result after reversal : 1       2       3       4       5  
                            

📘 Explanation

C Program to Reversing Array Elements in C Programming
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.