C Program to Reverse Elements of an Array

Here, I’m going to share information about “C Program to Reverse Elements of an Array”. Let’s try to execute the task using this article. Let’s go.

C Program to Reverse Elements of an Array

C Program to Reverse Elements of an Array

Source Code

#include <stdio.h>
int main()
{
  int n, c, d, a[100], b[100];

  printf("Enter the number of elements in arrayn");
  scanf("%d", &n);

  printf("Enter array elementsn");

  for (c = 0; c < n ; c++)
    scanf("%d", &a[c]);

  // Copying elements into array b starting from the end of array a

  for (c = n - 1, d = 0; c >= 0; c--, d++)
    b[d] = a[c];

  // Copying reversed array into the original, we are modifying the original array.

  for (c = 0; c < n; c++)
    a[c] = b[c];

  printf("The array after reversal:n");

  for (c = 0; c < n; c++)
    printf("%dn", a[c]);

  return 0;
}

Conclusion

I hope this article helps you to learn the topic of “C Program to Reverse Elements of an Array”. If you face any issues please let me know via the comment section. Share this article with other C/C++ developers via social networks.

Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment