Rotate the array data structure 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.

Reverse of array:
Example-
Integer Array is {1,2,3,4,5}
Reverse Array is {5,4,3,2,1}

program-

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


output-

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

-In this program, we take a input of 5 numbers in first Array.
-then run the loop and traverse the first array from the last and store in second array from the start.
-We can traverse first array from the end by a[5-i-1].
-then we print the second array which is the required answer.




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!