Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace misc
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- // average(arithmetic mean, средно аритметично)
- int[] arr = { 3,4,5,6,7,8,9};
- int sum = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- sum += arr[i];
- }
- int average = sum / arr.Length;
- string arrToString = string.Join(' ', arr);
- Console.WriteLine($"average of [{arrToString}] is: {average:0.00}"); //:0.00 forces the output to be printed with 2 decimals.
- // geometric mean (средно геометрично)
- int product = 1;
- for (int i = 0; i < arr.Length; i++)
- {
- product *= arr[i];
- }
- double geometricMean = Math.Pow((double)product, (1/(double)arr.Length)); //(double) is for casting to double since Math.Pow works with floats and doubles and not ints.
- // 1/power == nth-root
- Console.WriteLine($"geometric mean of [{arrToString}] is: {geometricMean:0.00}");
- //root mean square - средноквадратично (wiki) - домашното по PHP
- int sumOfSquares = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- sumOfSquares += arr[i] * arr[i];
- }
- //homework assignment states sqrt(sum num^2)
- double rootMeanSquare = Math.Sqrt(sumOfSquares) / arr.Length; // since math.sqrt returns a double, , '/' is considered a floating point division and not integer division (5.0/2=2.5)
- Console.WriteLine($"geometric mean of [{arrToString}] is: {rootMeanSquare:0.00}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement