

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
Find Harmonic mean using Arithmetic mean and Geometric mean using C++.
Here we will see how to get the Harmonic mean using the arithmetic mean and the geometric mean. The formula for these three means are like below −
- Arithmetic Mean − (a + b)/2
- Geometric Mean − $$\sqrt{\lgroup a*b\rgroup}$$
- Harmonic Mean − 2ab/(a+b)
The Harmonic Mean can be expressed using arithmetic mean and geometric mean using this formula −
$$HM=\frac{GM^{2}}{AM}$$
Example
#include <iostream> #include <cmath> using namespace std; double getHarmonicMean(int a, int b) { double AM, GM, HM; AM = (a + b) / 2; GM = sqrt(a * b); HM = (GM * GM) / AM; return HM; } int main() { int a = 5, b = 15; double res = getHarmonicMean(a, b); cout << "Harmonic Mean of " << a << " and " << b << " is " << res ; }
Output
Harmonic Mean of 5 and 15 is 7.5
- Related Questions & Answers
- Implement Harmonic mean and Quadratic mean in MySQL?
- Arithmetic Mean in c++?
- Arithmetic Mean in C programming
- Find a subset with greatest geometric mean in C++
- C++ code to find minimum arithmetic mean deviation
- Program for harmonic mean of numbers in C++
- How to Calculate the Geometric Mean of Return
- C++ Program for class interval arithmetic mean
- Absolute Deviation and Absolute Mean Deviation using NumPy
- How to find the mean for multiple columns in an R data frame using mean function not colMeans?
- Find Rolling Mean – Python Pandas
- Does HTTPS mean safe?
- Mean and Mode in SQL Server
- How to create boxplot using mean and standard deviation in R?
- Plot mean and standard deviation in Matplotlib
Advertisements