Left 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.

Left Shift in Array:

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

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]);
}
//left shift
for(int i=0;i< 5;i++)
{
b[i]=a[(1+i)%5];
}
printf("After left shiftn");
//Now traverse
for(i=0;i< 5;i++)
printf("%d,",b[i]);
}


output-

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

-In this program, we take a input of 5 numbers in Array.
-then we do the left shift by the b[i]=a[(1+i)%5];
run for every value of i.
-Left 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!