Skip to content

Instantly share code, notes, and snippets.

@Mulperi
Created April 24, 2019 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mulperi/9574840e3ccbeecfea09927e68fbad21 to your computer and use it in GitHub Desktop.
Save Mulperi/9574840e3ccbeecfea09927e68fbad21 to your computer and use it in GitHub Desktop.
Rainfall C#
using System;
public class Program
{
public static double GetAverage(double[] arr)
{
double sum = 0;
double amount = 0;
for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == 99999)
break;
if (arr[i] > 0)
{
sum += arr[i];
amount++;
}
}
return sum > 0 ? sum / amount : 0;
}
public static void Main()
{
double[] arr = {-1, 1, 3, 99999};
double[] arr2 = {99999};
double[] arr3 = {1, 2};
double[] arr4 = {1, 2, 99999, 5};
//Console.WriteLine(GetAverage(arr2));
Console.WriteLine(GetAverage(arr4));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment