Reverse array from middle by R4R Team

Array:

Array is the collection of different values having same data type.
-We have a integer Array that having all integer values.
-Character array is known as String.

What we do?

Example-
Array is {2,3,1,0,4,2}
//After Reverse from middle
Array is {1,3,2,2,4,0}

program-

#include < stdio.h>
int main()
{
int a[6],b[6];
int i;
printf("Enter 6 number in array\n");
//input in array
for(i=0;i< 6;i++){
scanf("%d",&a[i]);
}
//Now reverse first half
for(i=0;i< 3;i++)
{
b[i]=a[3-i-1];
}
//Now reverse second half
for(i=0;i< 3;i++)
{
b[3+i]=a[6-i-1];
}
//Now traverse
printf("Reverse array is\n");
for(i=0;i< 6;i++)
printf("%d,",b[i]);
}


output-

Enter 6 number in array
1 2 3 4 5 6
Reverse array is 3,2,1,6,5,4,




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!