//C program to illustrate how to rotate array
#include <stdio.h>

//Function to rotate array left by one position
void leftRotatebyOne(int arr[], int n)
{
    int temp=arr[0];
    for(int i=0;i<n-1;i++){
        arr[i]=arr[i+1];
    }
    arr[n-1]=temp;
}

//Function to rotate array left by d position
void leftRotate(int arr[],int d,int n)
{
    for(int i=0;i<d;i++){
        leftRotatebyOne(arr,n);
    }
}

//Function to print an array
void printArray(int arr[],int n)
{
    for(int i=0;i<n;i++){
        printf("%d ",arr[i]);
    }
    printf("\n");
}

int main() 
{
    int arr[]={1,2,3,4,5,6,7};
    int n=sizeof(arr)/sizeof(arr[0]);
    int d=2;

    //Rotate array left by d positions
    leftRotate(arr,d,n);
    
    printf("Array is rotated by %d positions is: ",d);
    printArray(arr,n);
    
    return 0;
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: