Advertisement
plamen27

Odd Even Position

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