#include<stdio.h>
int main() {
int a[100],n,pos,val,i,k,m;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&m); // m specifies number of times to be rotated
for(k=0;k<m;k++)
{
val=a[0];
for(i=0;i<n;i++)
{
a[i]=a[i+1];
}
a[n-1]=val;
}
printf("elements after left rotation are\n");
for(i=0;i<n;i++)
printf(" %d",a[i]);
}
int main() {
int a[100],n,pos,val,i,k,m;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
scanf("%d",&m); // m specifies number of times to be rotated
for(k=0;k<m;k++)
{
val=a[0];
for(i=0;i<n;i++)
{
a[i]=a[i+1];
}
a[n-1]=val;
}
printf("elements after left rotation are\n");
for(i=0;i<n;i++)
printf(" %d",a[i]);
}
i/p: 5
1 2 3 4 5
3
o/p: elements after left rotation are
4 5 1 2 3
No comments:
Post a Comment