VelizarAvramov

11. 5 Different Numbers

Nov 5th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _11._5_Different_Numbers
  4. {
  5.     class FiveDifferentNumbers
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //You will be given two numbers – a and b. Generate five numbers - n1, n2, n3, n4, n5, for which the following conditions
  10.             //are true: a ≤ n1 < n2 < n3 < n4 < n5 ≤ b. If there is no number in the given interval, which satisfies the conditions –
  11.             //print “No”.
  12.             int first = int.Parse(Console.ReadLine());
  13.             int second = int.Parse(Console.ReadLine());
  14.  
  15.             if (first + 4 >= second)
  16.             {
  17.                 Console.WriteLine("No");
  18.                 return;
  19.             }
  20.  
  21.             for (int i = first; i <= second-4; i++)
  22.             {
  23.                 for (int j = first+1; j <= second-3; j++)
  24.                 {
  25.                     for (int k = first+2; k <= second-2; k++)
  26.                     {
  27.                         for (int l = first+3; l <=second-1; l++)
  28.                         {
  29.                             for (int m = first+4; m <= second; m++)
  30.                             {
  31.                                 if (i<j && j<k && k<l && l<m)
  32.                                 {
  33.                                     Console.WriteLine($"{i} {j} {k} {l} {m}");
  34.                                 }
  35.                             }
  36.                         }
  37.                     }
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment