-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWave_format.c
More file actions
52 lines (51 loc) · 804 Bytes
/
Wave_format.c
File metadata and controls
52 lines (51 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
int main()
{
int n,i,j;
scanf("%d",&n);
int arr[n],a[n];
int temp;
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[i]>arr[j])
{
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
j=0;
for(i=n-1;i>=0;i--)
{
a[j]=arr[i];
j++;
}
for(i=0; i<n; i=i+2)
{
temp = a[i];
a[i] = a[i+1];
a[i+1] = temp;
}
if(n%2==0)
{
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}
else
{
for(i=0;i<n-1;i++)
{
printf("%d ",a[i]);
}
printf("%d",a[n]);
}
}