Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Excercise1
- {
- static void Main()
- {
- int n;
- Console.Write("Please enter a value for n: ");
- string input = Console.ReadLine();
- n = int.Parse(input);
- PrintOdd(n);
- Console.WriteLine(CalculateAverage(n));
- }
- static void PrintOdd(int n)
- {
- for (int i = 0; i <= n; i++)
- {
- if(i % 2 == 1)
- {
- Console.WriteLine(i);
- }
- }
- }
- static double CalculateAverage(int n)
- {
- int sum = 0;
- for (int i = 0; i <= n; i++)
- {
- sum += i;
- }
- return (double)sum / n;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement