C Program that interchanges the odd and even elements of an array.

//C Program that interchanges the odd and even elements of an array.
#include<stdio.h>
int main()
{
	int a[] = {1,2,3,4,5,6},i,tmp;
	for (i = 0; i <= 5; i = i + 2)
	{
		tmp = a[i];
		a[i] = a[i + 1];
		a[i + 1] = tmp;
	}
	for (i = 0; i <= 5; i++)
	{
		printf("%d\n", a[i]);
	}
	getch();
	return 0;
}

Output :
2
1
4
3
6
5



Leave a comment