blob: 7352cd7e9f53fb0171b300ad1cf8afad51269313 (
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#print
Write a program
pair(a,b)
which accepts as arguments two pointers to integers
and swaps the integers if necessary so that the
first argument points to the larger one; that is
int x,y;
x = 9;
y = 15;
pair( &x, &y);
results in x being 15 and y 9. Leave the program
on file "pair.c"; compile, test it, and type "ready".
#once #create tzaqc.c
main()
{
int x,y;
y=200;
x = 0;
pair(&y, &x);
if (x != 0 || y != 200)
return(1);
pair(&x,&y);
if (x != 200 || y != 0)
return(1);
x = 30;
y = 23097;
pair(&x,&y);
if (x != 23097 || y != 30)
return(1);
return(0);
}
#user
cc tzaqc.c pair.o
a.out
#succeed
pair(a, b)
int *a, *b;
{
int t;
if (*a <= *b) {
t = *a;
*a = *b;
*b = t;
}
}
#log
#next
33.1a 10
|