axeefectushka

Untitled

Oct 15th, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         int a, b;
  8.         Console.Write("Enter a: ");
  9.         a = Convert.ToInt32(Console.ReadLine());
  10.         Console.Write("Enter b: ");
  11.         b = Convert.ToInt32(Console.ReadLine());
  12.  
  13.         if ((a < 0 && b < 0) || a == b || (a < 0 && b == 0) || (a == 0 && b < 0))
  14.         {
  15.             Console.WriteLine("a and b are both below zero, or equal to it, or equal to each other, or one of them is below zero and the other is 0");
  16.         }
  17.         else
  18.         {
  19.             if(a>b)
  20.             {
  21.                 int tmp = a;
  22.                 a = b;
  23.                 b = tmp;
  24.             }
  25.             Console.WriteLine("If between a and b there are numbers, in binary form of which there are only four 1, then they will be displayed after this message");
  26.             for (int i=a;i<=b;i++)
  27.             {
  28.                 if (i < 0) continue;
  29.  
  30.                 int count = 0;
  31.                 int temp = i;
  32.                 while (temp > 0)
  33.                 {
  34.                     int temp1 = temp % 2;
  35.                     if (temp1 == 1) count++;
  36.                     temp /=2;
  37.                 }
  38.                 if (count == 4) Console.WriteLine(i);
  39.  
  40.             }
  41.             Console.ReadKey();
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment