Advertisement
ivoCod

C# Задача от SoftUni - 12. Equal Pairs (Еднакви двойки)

Apr 10th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 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 _12.Equal_Pairs
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Write("Въведете броя на двойките числа n: ");
  14.             int n = int.Parse(Console.ReadLine());
  15.             Console.WriteLine("Въведете числата за пресмятане, които са (2 * n) бр.: ");
  16.  
  17.             double prevPairSum = 0.0;
  18.             double currentPairSum = 0.0;
  19.             double difference = 0.0;
  20.             double differenceMax = double.MinValue;
  21.            
  22.  
  23.             for (int i = 0; i < n; i ++)
  24.             {
  25.                 var inputNum1 = double.Parse(Console.ReadLine());
  26.                 var inputNum2 = double.Parse(Console.ReadLine());
  27.  
  28.                 currentPairSum = (inputNum1 + inputNum2);
  29.                
  30.                 if (i > 0)
  31.                 {
  32.                     difference = Math.Abs(currentPairSum - prevPairSum);
  33.                     if (difference > differenceMax)
  34.                     {
  35.                         differenceMax = difference;
  36.                     }
  37.                 }
  38.  
  39.                 prevPairSum = currentPairSum;
  40.  
  41.             }
  42.  
  43.             if (difference == 0)
  44.             {
  45.                 Console.WriteLine($"Yes, value={currentPairSum}");
  46.             }
  47.             else if (difference != 0)
  48.             {
  49.                 Console.WriteLine($"No, maxdiff={differenceMax}");
  50.             }
  51.  
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement