Calculate Average of Array Elements
C++
Easy
8 views
Problem Description
Write a program that takes an array of numbers and calculates their average. This helps understand array traversal and basic arithmetic operations.
Logic: Sum all elements and divide by total count
Official Solution
#include <iostream>
using namespace std;
void question1_array_average() {
int marks[] = {85, 90, 78, 92, 88};
int total = 0;
int size = 5;
for(int i = 0; i < size; i++) {
total = total + marks[i];
}
float average = (float)total / size;
cout << "Average marks: " << average << endl;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!