Advertisement
Pazzobg

Programming Basics / 5.Loops / 17.OddEvenPosition

Feb 17th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _0.Practice
  4. {
  5.     class Practice
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             double oddSum = 0.0;
  11.             double oddMin = double.MaxValue;
  12.             double oddMax = double.MinValue;
  13.             double evenSum = 0.0;
  14.             double evenMin = double.MaxValue;
  15.             double evenMax = double.MinValue;
  16.  
  17.             for (int i = 1; i <= n; i++)
  18.             {
  19.                 var input = double.Parse(Console.ReadLine());
  20.  
  21.                 if (i % 2 != 0)
  22.                 {
  23.                     oddSum += input;
  24.                     if (input < oddMin)
  25.                     {
  26.                         oddMin = input;
  27.                     }
  28.                     if (input > oddMax)
  29.                     {
  30.                         oddMax = input;
  31.                     }
  32.                 }
  33.                 else
  34.                 {
  35.                     evenSum += input;
  36.                     if (input < evenMin)
  37.                     {
  38.                         evenMin = input;
  39.                     }
  40.                     if (input > evenMax)
  41.                     {
  42.                         evenMax = input;
  43.                     }
  44.                 }
  45.             }
  46.  
  47.             Console.WriteLine($"OddSum = {oddSum}");
  48.             if (oddMin != double.MaxValue)
  49.                 Console.WriteLine($"OddMin = {oddMin}");
  50.             else
  51.                 Console.WriteLine("OddMin = No");
  52.             if (oddMax != double.MinValue)
  53.                 Console.WriteLine($"OddMax = {oddMax}");
  54.             else
  55.                 Console.WriteLine("OddMax = No");
  56.             Console.WriteLine($"EvenSum = {evenSum}");
  57.             if (evenMin != double.MaxValue)
  58.                 Console.WriteLine($"EvenMin = {evenMin}");
  59.             else
  60.                 Console.WriteLine("EvenMin = No");
  61.             if (evenMax != double.MinValue)
  62.                 Console.WriteLine($"EvenMax = {evenMax}");
  63.             else
  64.                 Console.WriteLine("EvenMax = No");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement