QUESTION
Enter even number of elements and swap the adjacent elements of the ID array.
“TESTCASE_1”: “4\n10 20 30 40\n###—###SEPERATOR—###—\n20 10 40 30”, “TESTCASE_2”: “6\n11 12 13 14 15 16\n###—###SEPERATOR—###—\n12 11 14 13 16 15”, “TESTCASE_3”: “8\n2 8 9 4 8 6 5 8\n###—###SEPERATOR—###—\n8 2 4 9 6 8 8 5”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0
ANSWER
#include <stdio.h>
int main()
{
int n;
scanf("%d",&n);
int arr[n];
int i;
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
for(i=0;i<n;i=i+2)
{
int t=arr[i];
arr[i]=arr[i+1];
arr[i+1]=t;
printf("%d %d ",arr[i],arr[i+1]);
}
return 0;
}