/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
/*
input: len = 6, array[]={1,2,3,4,5,6}
output:(1,2)(3,4)(5,6)//set 1
(1,4)(2,6)(3,5)//set 2
(1,6)(4,5)(2,3)//set 3
(1,6)(5,3)(4,2)//set 4 invalid
so on
*/
struct pairSet{int p1; int p2;};
int main()
{ int a[]={1,2,3,4,5,6},i,j,k,count=0,len = sizeof(a)/sizeof(a[0]);;
struct pairSet ps[6];
printf("Set 1\n");
for(i=0;i<len;)
{ for(j=i+1;j<len;j++)
{ ps[count].p1 = a[i];
ps[count].p2 = a[j];
//printf("(%d,%d)\n",a,a[j]);
break;
} count++; i=i+2;
}
for(k=0;k<count;k++){printf("(%d,%d) ",ps[k].p1,ps[k].p2);}
printf("\n");
return 0;
}