📜  算术平均值

📅  最后修改于: 2021-04-28 16:47:40             🧑  作者: Mango

算术平均值,也称为平均值,是通过将两个或多个数字或变量相加然后除以数字或变量的数量而获得的数量。算术平均值在统计中很重要。

例如,假设仅涉及两个数量,则算术平均值可以通过将数量相加并除以2来简单地获得。

关于算术平均值的一些有趣事实:

  1. n个数字x1, x2, . . ., xn的均值x1, x2, . . ., xnx 。如果每个观测值增加p ,则新观测值的平均值为(x + p)
  2. n个数字x1, x2, . . ., xn的均值x1, x2, . . ., xnx 。如果每个观察值都减少p ,则新观察值的平均值为(x - p)
  3. n个数字x1, x2, . . ., xn的均值x1, x2, . . ., xnx 。如果每个观察值都乘以非零数p ,则新观察值的平均值为px
  4. n个数字x1, x2, . . ., xn的均值x1, x2, . . ., xnx 。如果将每个观察值除以非零数p ,则新观察值的平均值为(x/p)

算术平均值的公式:

如何找到算术平均值?
给定三个整数A,B和N,任务是在A和B之间找到N个算术平均值。我们基本上需要在算术级数中插入N个项。其中A和B是第一项和最后一项。

例子:

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

方法 :
设A 1 ,A 2 ,A 3 ,A 4 …A n为两个给定数字A和B之间的N个算术平均值。然后A,A 1 ,A 2 ….. A n ,B将处于算术级数。现在B =算术级数的(N + 2)项。所以 :
找出算术级数级数的(N + 2)项,其中d是公有差

B = A + (N + 2 - 1)d
B - A  = (N + 1)d

因此,共同差d由给出。

d = (B - A) / (N + 1)

我们有A的值和共同差( d )的值,现在我们可以找到A和B之间的所有N个算术平均值。

C++
// C++ program to find n arithmetic
// means between A and B
#include 
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


PHP


输出:
22 24 26 28 30

与算术平均值有关的基本程序

  • 使用算术平均值和几何平均值找到调和平均值
  • 类间隔算术平均值程序