Stanislavgr

03.Odd / Even Position_For-Loop- Excersise

Apr 10th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 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 _03.Odd___Even_Position
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. double n = double.Parse(Console.ReadLine());
  14.  
  15. double oddSum = 0;
  16. double oddMin = double.MaxValue;
  17. double oddMax = double.MinValue;
  18.  
  19. double evenSum = 0;
  20. double evenMin = double.MaxValue;
  21. double evenMax = double.MinValue;
  22.  
  23. for (int i = 1; i <= n; i++)
  24. {
  25. double num = double.Parse(Console.ReadLine());
  26.  
  27. if (i % 2 == 0)
  28. {
  29. evenSum += num;
  30. }
  31. if (num > evenMax)
  32. {
  33. evenMax = num;
  34. }
  35. if (num < evenMax)
  36. {
  37. evenMin = num;
  38. }
  39. if ((i % 2 == 1))
  40. {
  41. oddSum += num;
  42. }
  43. if (num > oddMax)
  44. {
  45. oddMax = num;
  46. }
  47. if (num < oddMax)
  48. {
  49. oddMin = num;
  50. }
  51. if (oddMin == oddMax || evenMin == evenMax)
  52. {
  53. Console.WriteLine("No");
  54. }
  55.  
  56.  
  57. Console.WriteLine($"OddSum={oddSum:f2}");
  58. Console.WriteLine($"OddMin={oddMin:f2}");
  59. Console.WriteLine($"OddMax={oddMax:f2}");
  60. Console.WriteLine($"EvenSum={evenSum:f2}");
  61. Console.WriteLine($"EvenMin={evenMin:f2}");
  62. Console.WriteLine($"EvenMax={evenMax:f2}");
  63. }
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment