LusienGG

[C#] Odd / Even Position

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