Interview Question Question description Ravi participated in TCS off campus interview at reputed institution, one of the technical question he has to complete with in the given time, where you need to sort the array in the waveform. There might be multiple possible output of the program. the following pattern output is appreciated. Function Description This is a simple method of solving this question which contains basic 2 steps and they are as follow Step : 1 – Sort the array in ascending order. Step : 2 – Swap all adjacent elements of the array
C Program


#include<stdio.h>

int main()

{

int n;

scanf("%d",&n);

int array[n];

int i,j,temp;

for(int i=0;i<n;i++)

scanf("%d",&array[i]);

for(i=0;i<n-1;i++)

{

for(j=i+1;j<n;j++)

{

if(array[i]>array[j])

{

temp=array[i];

array[i]=array[j];

array[j]=temp;

}

}

}

for(i=0;i<n-1;i+=2)

{

temp=array[i];

array[i]=array[i+1];

array[i+1]=temp;

}

for(int i=0;i<n;i++)

printf("%d ",array[i]);

return 0;

}