- Related Questions & Answers
- Average numbers in array in C Programming
- Add minimum number to an array so that the sum becomes even in C programming
- Concatenate a string given number of times in C++ programming
- Write a program to Delete a Tree in C programming
- Write a function that returns 2 for input 1 and returns 1 for 2 in C programming
- Ways to paint N paintings such that adjacent paintings don’t have same colors in C programming
- Surface Area and Volume of Hexagonal Prism in C programming
- Superperfect Number in C programming
- Super Prime in c programming
- Sums of ASCII values of each word in a sentence in c programming
- Sum triangle from an array in C programming
- C Programming for sum of the series 0.6, 0.06, 0.006, 0.0006, …to n terms
- C Programming for Sum of sequence 2, 22, 222, ………
- Sum of the numbers up to N that are divisible by 2 or 5 in c programming
- Sum of the first N terms of the series 5,12, 23, 38…. in C Programming

Arithmetic mean is the sum of a collection of numbers divided by the number of numbers in the collection.

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).

**Type 1**: Direct mean

Given the array and number of elements

**Input **- 1,2,3,4,5,6,7,8,9

**Output **- 5

**Explanation **- To calculate the arithmetic mean of all numbers, first perform addition of all the numbers, then make a variable responsible for the arithmetic mean and place addition/size in a variable say **armean**.

#include<iostream> using namespace std; int main(){ int n, i, sum=0; int arr[]={1,2,3,4,5,6,7,8,9}; n=9; for(i=0; i<n; i++) { sum=sum+arr[i]; } int armean=sum/n; cout<<"Arithmetic Mean = "<<armean; }

**Type 2**: Range and no of elements present I range is given.

Given three integers X, Y and N. Logic to find N Arithmetic means between X and Y.

N terms in an Arithmetic progression (no. of terms between X and Y)

X= first and Y= last terms.

**Input **- X = 22 Y = 34 N = 5

**Output **- 24 26 28 30 32

The Arithmetic progression series is

22 24 26 28 30 32 34

**Explanation**

Let X_{1}, X_{2}, X_{3}, X_{4}……X_{n} be N Arithmetic Means between two given numbers X and Y.

Then X, X_{1}, X_{2}, X_{3}, X_{4}……X_{n}, Y will be in Arithmetic Progression. Now Y = (N+2)^{th} term of the Arithmetic progression.

Finding the (N+2)^{th} term of the Arithmetic progression Series, where d is the Common Difference

Y = X + (N + 2 - 1)d Y - X = (N + 1)d

So the Common Difference d is given by.

d = (Y - X) / (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 X and Y.

#include<stdio.h> int main() { int X = 22, Y = 34, N = 5; float d = (float)(Y - X) / (N + 1); for (int i = 1; i <= N; i++) { printf("%3f ", (X + i * d)); } return 0; }

24.000000 26.000000 28.000000 30.000000 32.000000

Advertisements