n=int(input(‘enter the size : ‘))
k=int(input(‘number of rotation : ‘))
y=int(input(‘index : ‘))
b=[]
for i in range(n):
c=int(input())
b.append(c)
print(‘array before rotation :’,b)
for i in range(k):
temp=b[0]
for j in range(n-1):
b[j]=b[j+1]
b[n-1]=temp
print()
print(‘array after rotation : ‘,b)
print()
print(‘number at index :’,b[y])
By..Gunjan soni
#include
using namespace std;
void rotate(int arr[],int l,int h){
while(h>l){
int temp=arr[l];
arr[l]=arr[h];
arr[h]=temp;
l++;
h–;
}
}
int main()
{
int n;int d;
int arr[n];
cin>>n;
cin>>d;
for(int i=0;i>arr[i];
}
rotate(arr,0,n-d-1);
rotate(arr,n-d,n-1);
rotate(arr,0,n-1);
cout<<arr[1];
cout<<arr[2];
return 0;
}
#Python Programming
l=list(map(int,input().split(” “)))
k=int(input())
for i in range(k):
a1=l[-1]
l.insert(0,a1)
l[:]=l[:len(l)-1]
print(l)
n=int(input(‘enter the size : ‘))
k=int(input(‘number of rotation : ‘))
y=int(input(‘index : ‘))
b=[]
for i in range(n):
c=int(input())
b.append(c)
print(‘array before rotation :’,b)
for i in range(k):
temp=b[0]
for j in range(n-1):
b[j]=b[j+1]
b[n-1]=temp
print()
print(‘array after rotation : ‘,b)
print()
print(‘number at index :’,b[y])
By..Gunjan soni
Solution from Yogesh Jadhav(jadhavyogesh1228@gmail.com):
Under while loop by mistake k is k-; This not k- but correct as k–;
public class ArrayShift
{
public static void main(String[] args) {
int k=2;
int ct=-1;
int index=0;
int a[]=new int[]{3,4,5};
int b[]=new int[a.length];
while(k>=1){
for(int i=0;i<a.length;i++){
ct++;
if(i==a.length-1){
b[index]=a[i];
index++;
}
}
for(int j=0;j<ct;j++){
b[index]=a[j];
index++;
}
for(int c=0;c<a.length;c++){
a[c]=b[c];
}
k–;
ct=-1;
index=0;
}
for(int m=0;m<a.length;m++){
System.out.print(a[m]);
}
}
}
Solution from Yogesh Jadhav(jadhavyogesh1228@gmail.com):
public class ArrayShift
{
public static void main(String[] args) {
int k=2;
int ct=-1;
int index=0;
int a[]=new int[]{3,4,5};
int b[]=new int[a.length];
while(k>=1){
for(int i=0;i<a.length;i++){
ct++;
if(i==a.length-1){
b[index]=a[i];
index++;
}
}
for(int j=0;j<ct;j++){
b[index]=a[j];
index++;
}
for(int c=0;c<a.length;c++){
a[c]=b[c];
}
k–;
ct=-1;
index=0;
}
for(int m=0;m<a.length;m++){
System.out.print(a[m]);
}
}
}