← The C Language Lesson 20 of 77 · 5 XP

Warm-up: sum of numbers warm-up

Theory and problem statement

Machine translation, not yet reviewed by a native speaker.

You can add numbers up while reading them — into a piggy-bank variable:

int n, x, sum = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    sum += x;           // the same as sum = sum + x
}

Task. Read n, then n integers, and print their sum.

Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.