1 2 3 4 5 6 7 8 9 10 11 12 13
#include <stdio.h> void main() { int val, sum = 0, n = 0; while (1) { printf("data: "); scanf("%d", &val); if (val == -1) break; sum += val; n++; } printf("sum = %d, average = %.1f\n", sum, (double)sum / n); }