diff --git a/main.c b/main.c index fff61c4..bd1fbd1 100644 --- a/main.c +++ b/main.c @@ -1,23 +1,30 @@ #include - -typedef struct { - int x, y; -} Point; - -/* TODO: return the squared distance between a and b. */ -int dist2(Point a, Point b) { - int result = ((b.x - a.x) * (b.x - a.x)) + ((b.y - a.y) * (b.y - a.y)); - return result; -} +#include int main(void) { - int x1, y1, x2, y2; - scanf("%d %d %d %d", &x1, &y1, &x2, &y2); + int n; + if (scanf("%d", &n) != 1) + return 0; - Point a = {x1, y1}; - Point b = {x2, y2}; - /* TODO: build a from (x1, y1) and b from (x2, y2). */ + /* TODO: replace NULL with a malloc call that reserves room for n ints. */ + int *nums = malloc(n * sizeof n); + if (nums == NULL) { + fprintf(stderr, "no memory \n"); + /* TODO: allocation failed: print a message to stderr and return 1. */ + return 1; + } - printf("%d\n", dist2(a, b)); + for (int i = 0; i < n; i++) + scanf("%d", &nums[i]); + + long int sum = 0; + for (int i = 0; i < n; i++) + sum = sum + nums[i]; + + for (int i = n; n > 0; n--) { + printf("%d ", nums[n - 1]); + } + printf("%ld", sum); + free(nums); return 0; }