Swap adjacent elements of an array

C program to swap adjacent elements of a one dimensional array.

Program

#include<stdio.h>
#include<conio.h>
#define MAX 50

void read_array(int a[MAX], int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        printf("Element %d\t:",i+1);
        scanf("%d",&a[i]);
    }
}

void print_array(int a[MAX], int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        printf("Element %d\t:%d\n",i+1,a[i]);
    }
}

void swap_adj(int a[MAX], int n)
{
    int i, temp;
    for(i=0;i<n-1;i=i+2)
    {
        temp = a[i];
        a[i] = a[i+1];
        a[i+1] = temp;
    }
}

void main()
{
    int arr[MAX];
    int n;

    printf("Enter the number of elements in the array\t:");
    scanf("%d",&n);

    printf("Enter the elements of the array\n");
    read_array(arr, n);

    swap_adj(arr, n);

    printf("\nSwapped array\n");
    print_array(arr, n);

    getch();
}

Output

********** Run1 ********** 

Enter the number of elements in the array       :8
Enter the elements of the array
Element 1       :12
Element 2       :25
Element 3       :56
Element 4       :69
Element 5       :98
Element 6       :85
Element 7       :54
Element 8       :41

Swapped array
Element 1       :25
Element 2       :12
Element 3       :69
Element 4       :56
Element 5       :85
Element 6       :98
Element 7       :41
Element 8       :54


********** Run2 ********** 

Enter the number of elements in the array       :7
Enter the elements of the array
Element 1       :12
Element 2       :25
Element 3       :56
Element 4       :69
Element 5       :85
Element 6       :54
Element 7       :41

Swapped array
Element 1       :25
Element 2       :12
Element 3       :69
Element 4       :56
Element 5       :54
Element 6       :85
Element 7       :41