RadoslavStamboliev

11. Odd / Even Position

Jul 29th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 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 _11.Odd___Even_Position
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             int n = int.Parse(Console.ReadLine());
  15.             double oddSum = 0.0;
  16.             double evenSum = 0.0;
  17.             double oddMin = double.MaxValue;
  18.             double oddMax = double.MinValue;
  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)
  25.                 {
  26.                     evenSum += num;
  27.                     if (num < evenMin)
  28.                     {
  29.                         evenMin = num;
  30.                     }
  31.                      if (num > evenMax)
  32.                     {
  33.                         evenMax = num;
  34.                     }
  35.                 }
  36.                 else
  37.                 {
  38.                     oddSum += num;
  39.  
  40.                     if (num > oddMax) { oddMax = num; }
  41.                     if (num < oddMin) { oddMin = num; }
  42.                 }
  43.  
  44.             }
  45.  
  46.             if (n == 0)
  47.             {
  48.                 Console.WriteLine("Oddsum = 0, Oddmin = No, Oddmax = No, Evensum = 0, Evenmin = No, Evenmax = No");
  49.             }
  50.             else if (n == 1)
  51.             {
  52.                 Console.WriteLine($"Oddsum = {oddSum}, Oddmin = {oddMin}, Oddmax = {oddMax}, Evensum = 0, Evenmin = No, Evenmax = No");
  53.             }
  54.             else
  55.             {
  56.                 Console.WriteLine($"Oddsum = {oddSum}, Oddmin = {oddMin}, Oddmax = {oddMax}, Evensum = {evenSum}, Evenmin = {evenMin}, Evenmax = {evenMax}");
  57.             }
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment