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

Calculate Average

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a C program to calculate the average of elements in a 1D array. Input the size n, read n integers, calculate the sum, and then divide by n to find the average. Display the average formatted to 2 decimal places.

Example

Input:

5 10 20 30 40 50

Output:

30.00

Constraints

1 <= n <= 100

Input Format

n and n integers

Output Format

Float with 2 decimal places

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
3.00
Sum=15, 15/5 = 3.00
Sample #2
Public sample
4
1 1 1 2
1.25
Sum=5, 5/4 = 1.25
Sample #3
Public sample
3
-5 -5 -5
-5.00
Sum=-15, -15/3 = -5.00

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