Online Compiler C

#include <stdio.h> #include <limits.h> int main(void) { long long x, count = 0, sum = 0; long long mn = LLONG_MAX, mx = LLONG_MIN; // Enter integers separated by spaces/newlines; press Ctrl+D (Unix) or Ctrl+Z (Windows) to end while (scanf("%lld", &x) == 1) { if (x < mn) mn = x; if (x > mx) mx = x; sum += x; count++; } if (count == 0) { printf("No integers read.\n"); return 0; } double avg = (double)sum / (double)count; printf("count=%lld sum=%lld min=%lld max=%lld avg=%.6f\n", count, sum, mn, mx, avg); return 0; }
This program reads a sequence of integers from standard input, counts them, computes their sum, finds the minimum and maximum values, and calculates the average. It prints these statistics at the end.

- The program uses `long long` for variables, which is good for large integers, but the average is computed as a `double`. Consider what happens when `sum` is very large and you cast it to `double` — there might be a loss of precision for very large sums.
- The initial values for `mn` and `mx` are set to `LLONG_MAX` and `LLONG_MIN`. This works, but think about whether there is a simpler way to handle the first input value without relying on these extreme constants.