Advertisement
Guest User

Odd / Even Elements

a guest
Aug 26th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 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 Odd__Even_Elements_Sum_MIn_MAx
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. System.Threading.Thread.CurrentThread.CurrentCulture =
  14. System.Globalization.CultureInfo.InvariantCulture;
  15.  
  16. string[] numbers = Console.ReadLine().Split();
  17. decimal OddSum = 0;
  18. decimal OddMin = decimal.MaxValue;
  19. decimal OddMax = decimal.MinValue;
  20. decimal EvenSum = 0;
  21. decimal EvenMin = decimal.MaxValue;
  22. decimal EvenMax = decimal.MinValue;
  23.  
  24. for (int i = 0; i < numbers.Length; i += 2)
  25. {
  26.  
  27. decimal element = decimal.Parse(numbers[i]);
  28. OddSum = OddSum + element;
  29.  
  30. }
  31. for (int i = 1; i < numbers.Length; i += 2)
  32. {
  33.  
  34. decimal element = decimal.Parse(numbers[i]);
  35. EvenSum = EvenSum + element;
  36.  
  37. }
  38. for (int i = 0; i < numbers.Length; i++)
  39. {
  40. for (int j = 0; j < numbers.Length; j += 2)
  41. {
  42. decimal element = decimal.Parse(numbers[j]);
  43. OddMin = Math.Min(OddMin, element);
  44. OddMax = Math.Max(OddMax, element);
  45. }
  46. for (int k = 1; k < numbers.Length; k += 2)
  47. {
  48. decimal element = decimal.Parse(numbers[k]);
  49. EvenMin = Math.Min(EvenMin, element);
  50. EvenMax = Math.Max(EvenMax, element);
  51. }
  52. }
  53. Console.WriteLine("OddSum={0}, OddMin={1}, OddMax={2}, EvenSum={3}, EvenMin={4}, EvenMax={5}",
  54. (double)OddSum, (double)OddMin, (double)OddMax, (double)EvenSum, (double)EvenMin, (double)EvenMax);
  55.  
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement