summaryrefslogtreecommitdiff
path: root/2/3_int_arith/check-211.c
blob: 174b0f4c229b17d6d0fb4b998307ac38708d3fdc (plain)
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
#include <stdio.h>

void inplace_swap(int *x, int *y) {
    *y = *x ^ *y;
    *x = *x ^ *y;
    *y = *x ^ *y;
}

void reverse_array(int a[], int cnt) {
    int first, last;
    for (first = 0, last = cnt-1;
         first < last;
         first++,last--)
        inplace_swap(&a[first], &a[last]);
}

void print_array(int a[], int len) {
    int i;
    for (i = 0; i < len; i++)
        printf("%d", a[i]);
}

void main() {
    int a[] = {1,2,3,4,5, 6};
    reverse_array(a, 6);
    print_array(a, 6);
}