BSD 4_3_Tahoe release
[unix-history] / usr / lib / learn / C / L32.1a
CommitLineData
d6c1f319
C
1#print
2Write a program
3 pair(a,b)
4which accepts as arguments two pointers to integers
5and swaps the integers if necessary so that the
6first argument points to the larger one; that is
7 int x,y;
8 x = 9;
9 y = 15;
10 pair( &x, &y);
11results in x being 15 and y 9. Leave the program
12on file "pair.c"; compile, test it, and type "ready".
13#once #create tzaqc.c
14main()
15{
16 int x,y;
17
18 y=200;
19 x = 0;
20 pair(&y, &x);
21 if (x != 0 || y != 200)
22 return(1);
23 pair(&x,&y);
24 if (x != 200 || y != 0)
25 return(1);
26 x = 30;
27 y = 23097;
28 pair(&x,&y);
29 if (x != 23097 || y != 30)
30 return(1);
31 return(0);
32}
33#user
34cc tzaqc.c pair.o
35a.out
36#succeed
37pair(a, b)
38int *a, *b;
39{
40 int t;
41
42 if (*a <= *b) {
43 t = *a;
44 *a = *b;
45 *b = t;
46 }
47}
48#log
49#next
5033.1a 10