
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
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 Articles
- Implement Harmonic mean and Quadratic mean in MySQL?
- Swift Program to Find Harmonic Mean of the Numbers
- Arithmetic Mean in c++?
- What Is Arithmetic Mean?
- Find a subset with greatest geometric mean in C++
- Swift Program to Find Geometric Mean of the Numbers
- Arithmetic Mean in C programming
- Program for harmonic mean of numbers in C++
- C++ code to find minimum arithmetic mean deviation
- How to Calculate the Geometric Mean of Return
- Find the Arithmetic mean of first 10 natural numbers
- 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

Advertisements