
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Arithmetic Mean in C++
The Arithmetic Mean is just the average of numbers. In this program we will see how we can find the arithmetic mean from a set of numbers. The function will take the number set, and the number of elements. Out task is just adding each element, then divide it by number of elements that are passed.
Algorithm
arithmeticMean(dataset, n)
begin sum := 0 for each element e from dataset, do sum := sum + e done return sum/n end
Example
#include<iostream> using namespace std; float arithmetic_mean(float data[], int size) { float sum = 0; for(int i = 0; i<size; i++) { sum += data[i]; } return sum/size; } main() { float data_set[] = {25.3, 45.21, 78.56, 96.21, 22.12, 36.97}; cout << "Mean: " << arithmetic_mean(data_set, 6); }
Output
Mean: 50.7283
Advertisements