aboutsummaryrefslogtreecommitdiffstats
path: root/csci5271/hw1/hw1p4.c
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2021-09-28 21:12:58 -0500
committerMatt Strapp <matt@mattstrapp.net>2021-09-28 21:12:58 -0500
commit76196e49deaad521924b14fcda963033fd1405ef (patch)
tree14411889978756411a6a968fa8558717d790c3fb /csci5271/hw1/hw1p4.c
parentcommit work done (diff)
downloadhomework-76196e49deaad521924b14fcda963033fd1405ef.tar
homework-76196e49deaad521924b14fcda963033fd1405ef.tar.gz
homework-76196e49deaad521924b14fcda963033fd1405ef.tar.bz2
homework-76196e49deaad521924b14fcda963033fd1405ef.tar.lz
homework-76196e49deaad521924b14fcda963033fd1405ef.tar.xz
homework-76196e49deaad521924b14fcda963033fd1405ef.tar.zst
homework-76196e49deaad521924b14fcda963033fd1405ef.zip
do more of it
Signed-off-by: Matt Strapp <matt@mattstrapp.net>
Diffstat (limited to 'csci5271/hw1/hw1p4.c')
-rw-r--r--csci5271/hw1/hw1p4.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/csci5271/hw1/hw1p4.c b/csci5271/hw1/hw1p4.c
index e449de5..4526e43 100644
--- a/csci5271/hw1/hw1p4.c
+++ b/csci5271/hw1/hw1p4.c
@@ -1,11 +1,13 @@
#include <stdio.h>
/* Reverse the elements from FROM to TO, inclusive */
-void reverse_range(int *a, int from, int to) {
+void reverse_range(int *a, int from, int to)
+{
unsigned int *p = &a[from];
unsigned int *q = &a[to];
/* Until the pointers move past each other: */
- while (!(p == q + 1 || p == q + 2)) {
+ while (!(p == q + 1 || p == q + 2))
+ {
/* Swap *p with *q, without using a temporary variable */
*p += *q; /* *p == P + Q */
*q = *p - *q; /* *q == P + Q - Q = P */
@@ -15,11 +17,14 @@ void reverse_range(int *a, int from, int to) {
q--;
}
}
-int main() {
+
+int main()
+{
int a[10] = {255, 0, -65536, 2147483647, -2147483648,
- -1, 0, 1, 2, 3};
- reverse_range(a, 0, 9);
- for (int i = 0; i < 10; i++) {
+ -1, 0, 1, 2, 3};
+ reverse_range(a, 9, 0);
+ for (int i = 0; i < 10; i++)
+ {
printf("%d ", a[i]);
}
printf("\n");