Advertisement
wingman007

PrintOddCalculateAverage

Sep 21st, 2016
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1.  
  2. using System;
  3. class Excercise1
  4. {
  5.     static void Main()
  6.     {
  7.         int n;
  8.         Console.Write("Please enter a value for n: ");
  9.         string input = Console.ReadLine();
  10.         n = int.Parse(input);
  11.         PrintOdd(n);
  12.         Console.WriteLine(CalculateAverage(n));
  13.     }
  14.  
  15.     static void PrintOdd(int n)
  16.     {
  17.         for (int i = 0; i <= n; i++)
  18.         {
  19.             if(i % 2 == 1)
  20.             {
  21.                 Console.WriteLine(i);
  22.             }
  23.         }
  24.     }
  25.  
  26.     static double CalculateAverage(int n)
  27.     {
  28.         int sum = 0;
  29.         for (int i = 0; i <= n; i++)
  30.         {
  31.             sum += i;
  32.         }
  33.         return (double)sum / n;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement