lesson 9 pointers

This commit is contained in:
deck committed 2026-10-07 21:42:19 +02:00
1 parent 70d8d3dc17
commit cfb394d1bd
1 file changed
+9 -18
+9 -18
View File
@@ -1,25 +1,16 @@
#include <stdio.h> #include <stdio.h>
#include <stdnoreturn.h>
/* Return value limited to the range lo..hi (lo <= hi is guaranteed). */ void swap(int *a, int *b) {
int clamp(int value, int lo, int hi) { int temp = *a;
/* TODO: return lo, hi, or value itself, whichever applies. */ *a = *b;
int result = value; *b = temp;
if (result > hi) {
result = hi;
} else if (result < lo) {
result = lo;
}
return result;
} }
int main(void) { int main(void) {
int lo, hi, n; int a, b;
scanf("%d %d", &lo, &hi); scanf("%d %d", &a, &b);
scanf("%d", &n); swap(&a, &b);
for (int i = 0; i < n; i++) { printf("%d %d\n", a, b);
int x;
scanf("%d", &x);
printf("%d\n", clamp(x, lo, hi));
}
return 0; return 0;
} }