Advertisement
SomeoneX

Homework - 02. Half Sum Element

Nov 14th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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 Homework___02.Half_Sum_Element
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int countOfNum = int.Parse(Console.ReadLine());
  14.  
  15. int biggestNum = int.MinValue;
  16. int sumNums = 0;
  17.  
  18. for (int i = 0; i < countOfNum; i++)
  19. {
  20. int num = int.Parse(Console.ReadLine());
  21.  
  22. if (num > biggestNum )
  23. {
  24. biggestNum = num;
  25. }
  26.  
  27. sumNums += num;
  28.  
  29. }
  30.  
  31. double finalResult = sumNums - biggestNum;
  32.  
  33. if (biggestNum == finalResult)
  34. {
  35. Console.WriteLine("Yes");
  36. Console.WriteLine($"Sum = {finalResult}");
  37. }
  38. else
  39. {
  40. double finalSum = Math.Abs(biggestNum - finalResult);
  41.  
  42. Console.WriteLine("No");
  43. Console.WriteLine($"Diff = {finalSum}");
  44. }
  45. }
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement