Previous Next
0 / 21
Module DEMO-32-106DEMO-C-32

Sum of Array Elements

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a C program to compute the sum of all elements in a 1D array. The program should first read the number of elements n, then read n integers into an array, and finally compute and print the total sum.

Example

Input:

5 1 2 3 4 5

Output:

15

Constraints

1 <= n <= 100, elements within integer range.

Input Format

Integer n followed by n integers.

Output Format

The sum of the elements.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
5
1 2 3 4 5
15
1+2+3+4+5 = 15
Sample #2
Public sample
3
-5 -5 -5
-15
Sum of negative numbers.
Sample #3
Public sample
1
100
100
Single element array.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings