Right shift in 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.

Right Shift in Array:

Example-
Array is {1,2,3,4,5}
After right Shift {5,1,2,3,4}

program-

#include < stdio.h>
int main()
{
int a[6],b[6];
int i;
printf("Enter number in array\n");
//input in array
for(i=0;i< 5;i++){
scanf("%d",&a[i]);
}
//right shift
for(int i=0;i< 5;i++)
{
b[(1+i)%5]=a[i];
}
//Now traverse
printf("After right shift\n");
for(i=0;i< 5;i++)
printf("%d,",b[i]);
}


output-

Enter number in array
1 2 3 4 5
After right shift
5,1,2,3,4,

-In this program, we take a input of 5 numbers in Array.
-then we do the Right shift by the b[(1+i)%5]=a[i];
-run for every value of i.
-Right shift array is store in another Array then we print that.




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!