Question--
A left rotation operation on an array shifts each of the array's elements unit to the left. For example, if left rotations are performed on array , then the array would become .
Given an array of integers and a number, , perform left rotations on the array. Return the updated array to be printed as a single line of space-separated integers in c.
Solution--
#include<stdio.h>
int main()
{
int n,d,i=0,j=0,r,s;
scanf("%d %d\n",&n,&d);
int a[n];
char temp;
do
{
scanf("%d%c",&a[i],&temp);
i++;
}while(temp!='\n');
while(j!=d)
{
r=a[n-1];
for(i=n-2;i>=0;i--)
{
s=a[i];
a[i]=r;
r=s;
}
a[n-1]=r;
j++;
}
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
ConversionConversion EmoticonEmoticon