Swap Elements

Given an array of even size the task is to break the array into two equal parts and swap the respective elements.

Example:

Consider an array of size 5.

123456

Right shifted array.

456123

Note: The array should be virtually divided into two parts.

C
#include <stdio.h>
int main()
{
    int n=0,c=0,temp=0;
    printf("Enter the array size: ");
    scanf("%d",&n);
    if(n%2==0)
    {
        int a[n];
        printf("Enter the array elements:-\n");
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
        }
        c=n/2;
        for(int i=0;i<n/2;i++)
        {
            temp=a[i];
            a[i]=a[c];
            a[c]=temp;
            c++;
        }
        for(int i=0;i<n;i++)
        {
            printf("%d ",a[i]);
        }
    }
    else
    {
        printf("Array size should be even");
    }
    return 0;
}
C