Write a Program to Reverse Array in C

In this tutorial, we learn about program to reverse array in c, I think are you at the beginner level of programming that why you looking for reverse array in c.


If you know array-like take array of elements from user and display the array elements using loops than good and if not then learn my tutorials on the array or from elsewhere but learn basics of the array and both things you can't do then no problem I will share problem in a very clear way. so, you can understand each step easily. Now, I am not taking much of your time.


write a program to reverse array or string

Program to reverse array in c

In the future I will share reverse array in java, Incoming java program we use the same concept but you find a difference in syntax of the language. so, I hope you known this concept for future use.

Source Code:

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

  printf("Enter the number of elements in array");

   scanf("%d",&n);

  printf("\nEnter array elements\n");

   for(c=0;c<n;c++)
   {
    scanf("%d",&a[c]);
   }
   for(c=n-1,d=0;c>=0;c--,d++)
   {
    b[d]=a[c];
   }
   for(c=0;c<n;c++)
   {
    a[c]=b[c];
   }
  printf("\nReverse array is \n");
   for(c=0;c<n;c++)
   {
    printf("%d\n",a[c]);
   }
 return 0;
}


Output:



Enter the number of elements in array: 8

Enter array elements
80
70
60
50
40
30
20
10

Reverse array is
10
20
30
40
50
60
70
80

--------------------------------

In the above article, We use loops to solve program to reverse array in c and if you know something new then please comment or send mail to featured and for contribution to codeamy.in and we also share reverse array java program soon.

Happy Coding!! ๐Ÿ˜Š

No comments:

If you have any doubts, Please let me know

Powered by Blogger.