MiroslavKisov

Even_Odd_Position

Jul 29th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 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 Even_Odd_Position
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             if(n==0)
  15.             {
  16.                 Console.WriteLine("oddsum 0,");
  17.                 Console.WriteLine("oddmin no,");
  18.                 Console.WriteLine("oddmax no,");
  19.                 Console.WriteLine("evensum 0,");
  20.                 Console.WriteLine("evenmin no,");
  21.                 Console.WriteLine("evenmax no");
  22.             }
  23.             else
  24.             {
  25.                 double oddSum = 0.0;
  26.                 double oddMax = double.MinValue;
  27.                 double oddMin = double.MaxValue;
  28.                 double evenSum = 0.0;
  29.                 double evenMax = double.MinValue;
  30.                 double evenMin = double.MaxValue;
  31.                 for (int i = 1; i <= n; i++)
  32.                 {
  33.                     double num = double.Parse(Console.ReadLine());
  34.                     if (i % 2 != 0)
  35.                     {
  36.                         oddSum = oddSum + num;
  37.                         if(num>=oddMax)
  38.                         {
  39.                             oddMax = num;
  40.                         }
  41.                         if(num<=oddMin)
  42.                         {
  43.                             oddMin = num;
  44.                         }
  45.                     }
  46.                     else if(i%2==0)
  47.                     {
  48.                         evenSum = evenSum + num;
  49.                         if (num >= evenMax)
  50.                         {
  51.                             evenMax = num;
  52.                         }
  53.                         if (num <= evenMin)
  54.                         {
  55.                             evenMin = num;
  56.                         }
  57.                     }
  58.                 }
  59.                 if(n==1)
  60.                 {
  61.                     Console.WriteLine("oddsum {0},",oddSum);
  62.                     Console.WriteLine("oddmin {0},",oddMin);
  63.                     Console.WriteLine("oddmax {0},",oddMax);
  64.                     Console.WriteLine("evensum 0,");
  65.                     Console.WriteLine("evenmin no,");
  66.                     Console.WriteLine("evenmax no");
  67.                 }
  68.                 else
  69.                 {
  70.                     Console.WriteLine("oddsum {0},", oddSum);
  71.                     Console.WriteLine("oddmin {0},", oddMin);
  72.                     Console.WriteLine("oddmax {0},", oddMax);
  73.                     Console.WriteLine("evensum {0},",evenSum);
  74.                     Console.WriteLine("evenmin {0},",evenMin);
  75.                     Console.WriteLine("evenmax {0}",evenMax);
  76.                 }
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment