Find combined mean and variance of two series | C # program to find combined mean and variance of two series . ; Function to find mean of series . ; Function to find the standard deviation of series . ; Function to find combined variance of two different series . ; mean1 and mean2 are the mean of two arrays . ; sd1 and sd2 are the standard deviation of two array . ; combinedMean is variable to store the combined mean of both array . ; d1_square and d2_square are the combined mean deviation . ; combinedVar is variable to store combined variance of both array . ; Driver code ; Function call to combined mean .
using System ; class GFG { static float mean ( int [ ] arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + arr [ i ] ; float mean = ( float ) sum / n ; return mean ; } static float sd ( int [ ] arr , int n ) { float sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + ( arr [ i ] - mean ( arr , n ) ) * ( arr [ i ] - mean ( arr , n ) ) ; float sdd = sum / n ; return sdd ; } static float combinedVariance ( int [ ] arr1 , int [ ] arr2 , int n , int m ) { float mean1 = mean ( arr1 , n ) ; float mean2 = mean ( arr2 , m ) ; Console . Write ( " Mean1 : ▁ " + mean1 + " ▁ " ) ; Console . WriteLine ( " Mean2 : ▁ " + mean2 ) ; float sd1 = sd ( arr1 , n ) ; float sd2 = sd ( arr2 , m ) ; Console . Write ( " StandardDeviation1 : ▁ " + sd1 + " ▁ " ) ; Console . WriteLine ( " StandardDeviation2 : ▁ " + sd2 + " ▁ " ) ; float combinedMean = ( float ) ( n * mean1 + m * mean2 ) / ( n + m ) ; Console . WriteLine ( " Combined ▁ Mean : ▁ " + combinedMean + " ▁ " ) ; float d1_square = ( mean1 - combinedMean ) * ( mean1 - combinedMean ) ; float d2_square = ( mean2 - combinedMean ) * ( mean2 - combinedMean ) ; Console . Write ( " d1 ▁ square : ▁ " + d1_square + " ▁ " ) ; Console . WriteLine ( " d2 _ square : ▁ " + d2_square ) ; float combinedVar = ( n * ( sd1 + d1_square ) + m * ( sd2 + d2_square ) ) / ( n + m ) ; return combinedVar ; } public static void Main ( ) { int [ ] arr1 = { 23 , 45 , 34 , 78 , 12 , 76 , 34 } ; int [ ] arr2 = { 65 , 67 , 34 , 23 , 45 } ; int n = arr1 . Length ; int m = arr2 . Length ; Console . WriteLine ( " Combined ▁ Variance : ▁ " + combinedVariance ( arr1 , arr2 , n , m ) ) ; } }