-
Notifications
You must be signed in to change notification settings - Fork 9
/
Q2_fix34.c
52 lines (43 loc) · 863 Bytes
/
Q2_fix34.c
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
/*
============================================================================
Name : lab10_a2.c
Author :
Version :
Copyright : Your copyright notice
Description : Hello World in C, Ansi-style
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
void swap(int N, int arr[], int k, int l)
{
int temp;
temp = arr[k];
arr[k] = arr[l];
arr[l] = temp;
}
int main(void) {
int N, i, j;
int index_to_be_changed;
scanf("%d", &N);
int arr[N];
for(i = 0; i < N;i++)
{
scanf("%d",&arr[i]);
}
for(i = 0; i < N-1; i++)
{
if(arr[i] == 3)
{
index_to_be_changed = i+1;
for(j = 0; j < N; j++)
{
if(arr[j] == 4 && arr[j-1] != 3)
swap(N, arr, index_to_be_changed, j);
}
}
}
for(i = 0; i < N; i++)
printf("%d ", arr[i]);
return 0;
}