Advertisement
Guest User

Half Sum Element

a guest
May 31st, 2017
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         int n = int.Parse(Console.ReadLine());
  7.         double firstNumber = double.Parse(Console.ReadLine());
  8.         double max = firstNumber;
  9.         double counter = max;
  10.         for (int i = 0; i < n-1; i++)
  11.         {
  12.             double number = double.Parse(Console.ReadLine());
  13.             counter += number;
  14.             if (number > max)
  15.             {
  16.                 max = number;
  17.             }
  18.             //else
  19.            // {
  20.            //     counter += number;
  21.            // }
  22.         }
  23.         counter -= max;
  24.         if (max == counter)
  25.         {
  26.             Console.WriteLine("Yes, sum = {0}", max);
  27.         }
  28.         else
  29.         {
  30.             Console.WriteLine("No, diff = {0}", Math.Abs(counter - max));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement