Arithmetic mean, also called the average or average value, is the quantity obtained by summing two or more numbers or variables and then dividing by the number of numbers or variables. The arithmetic mean is important in statistics.
For example, Let’s say there are only two quantities involved, the arithmetic mean is obtained simply by adding the quantities and dividing by 2.
Some interesting fact about Arithmetic Mean :
- The mean of n numbers x1, x2, . . ., xn is x. If each observation is increased by p, the mean of the new observations is (x + p).
- The mean of n numbers x1, x2, . . ., xn is x. If each observation is decreased by p, the mean of the new observations is (x – p).
- The mean of n numbers x1, x2, . . ., xn is x. If each observation is multiplied by a nonzero number p, the mean of the new observations is px.
- The mean of n numbers x1, x2, . . ., xn is x. If each observation is divided by a nonzero number p, the mean of the new observations is (x/p).
Formula of Arithmetic Mean:

How to find Arithmetic Mean ?
Given three integers A, B and N the task is to find N Arithmetic means between A and B. We basically need to insert N terms in an Arithmetic progression. where A and B are first and last terms.
Examples:
Input : A = 20 B = 32 N = 5
Output : 22 24 26 28 30
The Arithmetic progression series is
20 22 24 26 28 30 32
Input : A = 5 B = 35 N = 5
Output : 10 15 20 25 30
Approach :
Let A1, A2, A3, A4……An be N Arithmetic Means between two given numbers A and B . Then A, A1, A2 ….. An, B will be in Arithmetic Progression. Now B = (N+2)th term of the Arithmetic progression. So :
Finding the (N+2)th term of the Arithmetic progression Series, where d is the Common Difference
B = A + (N + 2 - 1)d
B - A = (N + 1)d
So the Common Difference d is given by.
d = (B - A) / (N + 1)
We have the value of A and the value of the common difference(d), now we can find all the N Arithmetic Means between A and B.
C++
// C++ program to find n arithmetic
// means between A and B
#include <bits/stdc++.h>
using namespace std;
// Prints N arithmetic means between
// A and B.
void printAMeans(int A, int B, int N)
{
// calculate common difference(d)
float d = (float)(B - A) / (N + 1);
// for finding N the arithmetic
// mean between A and B
for (int i = 1; i <= N; i++)
cout << (A + i * d) << " ";
}
// Driver code to test above
int main()
{
int A = 20, B = 32, N = 5;
printAMeans(A, B, N);
return 0;
}
Java
// java program to illustrate
// n arithmetic mean between
// A and B
import java.io.*;
import java.lang.*;
import java.util.*;
public class GFG {
// insert function for calculating the means
static void printAMeans(int A, int B, int N)
{
// Finding the value of d Common difference
float d = (float)(B - A) / (N + 1);
// for finding N the Arithmetic
// mean between A and B
for (int i = 1; i <= N; i++)
System.out.print((A + i * d) + " ");
}
// Driver code
public static void main(String args[])
{
int A = 20, B = 32, N = 5;
printAMeans(A, B, N);
}
}
Python3
# Python3 program to find n arithmetic
# means between A and B
# Prints N arithmetic means
# between A and B.
def printAMeans(A, B, N):
# Calculate common difference(d)
d = (B - A) / (N + 1)
# For finding N the arithmetic
# mean between A and B
for i in range(1, N + 1):
print(int(A + i * d), end = " ")
# Driver code
A = 20; B = 32; N = 5
printAMeans(A, B, N)
# This code is contributed by Smitha Dinesh Semwal
C#
// C# program to illustrate
// n arithmetic mean between
// A and B
using System;
public class GFG {
// insert function for calculating the means
static void printAMeans(int A, int B, int N)
{
// Finding the value of d Common difference
float d = (float)(B - A) / (N + 1);
// for finding N the Arithmetic
// mean between A and B
for (int i = 1; i <= N; i++)
Console.Write((A + i * d) + " ");
}
// Driver code
public static void Main()
{
int A = 20, B = 32, N = 5;
printAMeans(A, B, N);
}
}
// Contributed by vt_m
JavaScript
<script>
// Javascript program to find n arithmetic
// means between A and B
// Prints N arithmetic means between
// A and B.
function printAMeans(A, B, N)
{
// Calculate common difference(d)
let d = (B - A) / (N + 1);
// For finding N the arithmetic
// mean between A and B
for(let i = 1; i <= N; i++)
document.write((A + i * d) + " ");
}
// Driver code
let A = 20, B = 32, N = 5;
printAMeans(A, B, N);
// This code is contributed by souravmahato348
</script>
PHP
<?php
// PHP program to find n arithmetic
// means between A and B
// Prints N arithmetic means
// between A and B.
function printAMeans($A, $B, $N)
{
// calculate common
// difference(d)
$d = ($B - $A) / ($N + 1);
// for finding N the arithmetic
// mean between A and B
for ($i = 1; $i <= $N; $i++)
echo ($A + $i * $d), " ";
}
// Driver Code
$A = 20; $B = 32;
$N = 5;
printAMeans($A, $B, $N);
// This code is Contributed by vt_m.
?>
Time Complexity: O(N)
Auxiliary Space: O(1)
Basic Program related to Arithmetic Mean
Similar Reads
The Google Foo Bar Challenge
The Google Foo bar challenge has been known for the last 5 years or more as a secret process of hiring developers and programmers all over the world. It is a secret process and the challenge consists of coding challenges of increasing difficulty as you go along. My Experience with the Google Foo Bar
2 min read
GeeksforGeeks Problem Of The Day (POTD) Solutions | December 2023
Welcome to the daily solutions of our PROBLEM OF THE DAY (POTD) for the month of December 2023. We will discuss the entire problem step-by-step and work towards developing an optimized solution. Refer the detailed list of POTD solutions for the month of December 2023 below, along with its POTD probl
2 min read
GeeksforGeeks Problem Of The Day (POTD) Solutions | Answer Key, Videos & Editorials
Are you finding it difficult to develop a habit of coding? GeeksforGeeks is providing some extra incentive to keep your motivation levels always up - The POTD (Problem Of The Day). Become a more consistent coder by solving one question every day in the GeeksforGeeks Problem Of The Day (POTD) event a
3 min read
GEEK-O-LYMPICS 2022 - May The Geeks Force Be With You!
Is it possible to have tons of fun while maintaining your competitive spirit? Totally! It is 100% possible. For the geeks who code hard and play harder, Geek-O-Lympics is back yet again this year. Join this fun and frolic event of the month where you'll get to code while enjoying tons of activities
4 min read
Khalsa College of Engineering and Technology Fest Experience (Tech Fest 2024)
Hey! I'm so excited to tell you about my awesome time at Tech Fest 2024 at Khalsa College of Engineering and Technology which was a cool event. I got to present my paper on "AI in Cybersecurity," and guess what? I won first prize! I made sure my presentation was fun and easy to understand. I used lo
2 min read
#geekstreak2024 â 21 Days POTD Challenge Powered By Deutsche Bank
Consistency is the key to success, but staying consistent can be challenging. To help motivate you on this journey, we're offering a stylish backpack from Deutsche Bank as a reward! All you need to do is maintain a 21-day streak of solving the Problem of the Day (POTD) on GeeksforGeeks, starting fro
2 min read
Geek Week 2021 - The Biggest Festival For Programmers
The month of October brings along with itself festive vibes, good food & so many holidays too! Add to all that, a bit of geeky-ness. GeeksforGeeks is here to be a part of your October journey with our own festival too because, why not? For all the programmers out there, Geek Week 2021 is finally
5 min read
11 Best Chatgpt Prompts for Affiliate Marketing
Affiliate marketing is a performance-based job where individuals or companies earn commissions for promoting products or services through referral links. There has been a growing number of people who are opting for this at-home method of earning and therefore efficiency becomes important. Here is wh
9 min read
Geeks Summer Carnival 2022 - Your Best Investment of the Year
"Buy the dip"... "Invest in XYZ Mutual Fund" ⦠"Invest in NFTs"... and many more investment advice you must be getting on a regular basis but what if we tell you that this summer, you are about to get a golden opportunity to invest in something that will be your best career investment of the year wi
5 min read
Geeks Summer Carnival - The Biggest Coding Festival is Back!
The opening breeze of summer has already blown - and like always, it has come up with a lot of positive and fun vibes. Some of you must be bringing out your shades and heading towards the beach, some of you would have planned to binge-watch on Netflix, and yes, how can we forget that IPL is also the
5 min read