Advertisement
Guest User

SumOfElements

a guest
Mar 24th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace SumOfElementsSequence
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10.  
  11. string inputLine = Console.ReadLine();
  12. string[] numbers = inputLine.Split(' ');
  13.  
  14.  
  15. double sum = 0;
  16. for (int i = 0; i < numbers.Length; i++)
  17. {
  18. int number = int.Parse(numbers[i]);
  19.  
  20.  
  21.  
  22.  
  23. }
  24. int[] myInts = numbers.Select(int.Parse).ToArray();
  25. int maxValue = myInts.Max();
  26. sum = myInts.Sum();
  27. Array.Sort(myInts);
  28. if (maxValue == (sum - maxValue))
  29. {
  30. Console.WriteLine("Yes, sum={0}",maxValue);
  31. }
  32. else
  33. {
  34. Console.WriteLine("No, diff={0}",Math.Abs(maxValue-(sum-maxValue)));
  35. }
  36.  
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement