Advertisement
Blizzardo1

Average

Jul 21st, 2011
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1.         static void Main(string[] args)
  2.         {
  3.             Console.Write("Type out the numbers with Spaces in between\r\nNumbers: ");
  4.             string[] Numbers = Console.ReadLine().Split(' ');
  5.             decimal[] AverageList = new decimal[Numbers.Length];
  6.             for (int i = 0; i < AverageList.Length; i++)
  7.             {
  8.                 AverageList[i] = decimal.Parse(Numbers[i]);
  9.             }
  10.             Console.WriteLine("Your Average is {0}\r\nPress any key to exit...", GetAverage(AverageList));
  11.             Console.ReadKey(true);
  12.         }
  13.  
  14.         static decimal GetAverage(decimal[] Average)
  15.         {
  16.             decimal d = 0.00M;
  17.             foreach (decimal dec in Average)
  18.             {
  19.                 d += dec;
  20.             }
  21.             d = d / Average.Length;
  22.             return d;
  23.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement