Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _03.Odd__Even_Position
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numberOfNumbers = int.Parse(Console.ReadLine());
- double oddSum = 0;
- double oddMin = double.MaxValue;
- double oddMax = double.MinValue;
- double evenSum = 0;
- double evenMin = double.MaxValue;
- double evenMax = double.MinValue;
- for (int i = 1; i <= numberOfNumbers; i++)
- {
- double number = double.Parse(Console.ReadLine());
- if (i % 2 == 0)//Even position
- {
- evenSum += number;
- if (number > evenMax)
- {
- evenMax = number;
- }
- if (number < evenMin)
- {
- evenMin = number;
- }
- }
- else if (i % 2 != 0)//Odd position
- {
- oddSum += number;
- if (number > oddMax)
- {
- oddMax = number;
- }
- if (number < oddMin)
- {
- oddMin = number;
- }
- }
- }
- if (oddMax != double.MinValue && oddMin != double.MaxValue)
- {
- Console.WriteLine($"OddSum={oddSum:f2},");
- Console.WriteLine($"OddMin={oddMin:f2},");
- Console.WriteLine($"OddMax={oddMax:f2},");
- }
- if (evenMax != double.MinValue && evenMin != double.MaxValue)
- {
- Console.WriteLine($"EvenSum={evenSum:f2},");
- Console.WriteLine($"EvenMin={evenMin:f2},");
- Console.WriteLine($"EvenMax={evenMax:f2}");
- }
- if (oddMax == double.MinValue && oddMin == double.MaxValue)
- {
- Console.WriteLine($"OddSum={oddSum:f2},");
- Console.WriteLine($"OddMin=No,");
- Console.WriteLine($"OddMax=No,");
- }
- if (evenMax == double.MinValue && evenMin == double.MaxValue)
- {
- Console.WriteLine($"EvenSum={evenSum:f2},");
- Console.WriteLine($"EvenMin=No,");
- Console.WriteLine($"EvenMax=No");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement