Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.41 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03._Odd___Even_Position
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             double OddSum = 0;
  11.             double OddMin = 0;
  12.             double OddMax = 0;
  13.             double EvenSum = 0;
  14.             double EvenMin = 0;
  15.             double EvenMax = 0;
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 double currentInput = double.Parse(Console.ReadLine());
  20.                 if (i % 2 == 0)//odd
  21.                 {
  22.                     if (i == 0)
  23.                     {
  24.                         OddMax = currentInput;
  25.                         OddMin = currentInput;
  26.                     }
  27.                     if (OddMax < currentInput)
  28.                     {
  29.                         OddMax = currentInput;
  30.                     }
  31.                     if (OddMin > currentInput)
  32.                     {
  33.                         OddMin = currentInput;
  34.                     }
  35.  
  36.                     OddSum += currentInput;
  37.                 }
  38.                 else
  39.                 {
  40.                     if (i == 1)
  41.                     {
  42.                         EvenMax = currentInput;
  43.                         EvenMin = currentInput;
  44.                     }
  45.                     if (EvenMax < currentInput)
  46.                     {
  47.                         EvenMax = currentInput;
  48.                     }
  49.                     if (EvenMin > currentInput)
  50.                     {
  51.                         EvenMin = currentInput;
  52.                     }
  53.                     EvenSum += currentInput;
  54.                 }
  55.             }
  56.             Console.WriteLine($"OddSum={OddSum:F2},");
  57.             if (n < 1)
  58.             {
  59.                 Console.WriteLine($"OddMin=No,");
  60.                 Console.WriteLine($"OddMax=No,");
  61.             }
  62.             else
  63.             {
  64.                 Console.WriteLine($"OddMin={OddMin:F2},");
  65.                 Console.WriteLine($"OddMax={OddMax:f2},");
  66.             }
  67.             Console.WriteLine($"EvenSum={EvenSum:f2},");
  68.             if (n < 2)
  69.             {
  70.                 Console.WriteLine($"EvenMin=No,");
  71.                 Console.WriteLine($"EvenMax=No");
  72.             }
  73.             else
  74.             {
  75.                 Console.WriteLine($"EvenMin={EvenMin:f2},");
  76.                 Console.WriteLine($"EvenMax={EvenMax:f2}");
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement