Advertisement
ina_abadjieva

Odd Even Positions

Feb 19th, 2016
1,441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 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 OddEvenPosition
  8. {
  9. class OddEvenPosition
  10. {
  11. static void Main(string[] args)
  12. {
  13. var n = double.Parse(Console.ReadLine());
  14. var oddsum = 0.0;
  15. var oddmin = 1000000.0;
  16. var oddmax = -1000000.0;
  17. var evensum = 0.0;
  18. var evenmin = 1000000.0;
  19. var evenmax = -1000000.0;
  20. for (int i = 1; i <= n; i++)
  21. {
  22. var num = double.Parse(Console.ReadLine());
  23. if (i % 2 != 0)
  24. {
  25. oddsum += num;
  26. if (num > oddmax) oddmax = num;
  27. else if (num < oddmin) oddmin = num;
  28. }
  29. else
  30. {
  31. evensum += num;
  32. if (num > evenmax) evenmax = num;
  33. else if (num < evenmin) evenmin = num;
  34. }
  35. }
  36. if (n == 0)
  37. {
  38. Console.WriteLine("Oddsum = 0, Oddmin = No, Oddmax = No, Evensum = 0, Evenmin = No, Evenmax = No");
  39. }
  40. else if (n==1)
  41. {
  42. Console.WriteLine("Oddsum = {0}, Oddmin = {1}, Oddmax = {2}, Evensum = 0, Evenmin = No, Evenmax = No", oddsum, oddmin, oddmax);
  43. }
  44. else
  45. {
  46. Console.WriteLine("Oddsum = {0}, Oddmin = {1}, Oddmax = {2}, Evensum = {3}, Evenmin = {4}, Evenmax = {5}", oddsum, oddmin, oddmax, evensum, evenmin, evenmax);
  47. }
  48.  
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement