axeefectushka

Untitled

Oct 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 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.         if (a <= 0 && b <= 0)
  13.         {
  14.             Console.WriteLine("a and b are both below zero, or equal to it, or one of them is below zero and the other is 0");
  15.         }
  16.         else
  17.         {
  18.             if(a>b)
  19.             {
  20.                 int tmp = a;
  21.                 a = b;
  22.                 b = tmp;
  23.             }
  24.             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");
  25.             for (int i=a;i<=b;i++)
  26.             {
  27.                 if (i < 0) continue;
  28.  
  29.                 int count = 0;
  30.                 int temp = i;
  31.                 while (temp > 0)
  32.                 {
  33.                     int temp1 = temp % 2;
  34.                     if (temp1 == 1) count++;
  35.                     temp /=2;
  36.                 }
  37.                 if (count == 4) Console.WriteLine(i);
  38.             }
  39.             Console.ReadKey();
  40.         }
  41.     }
  42. }
Add Comment
Please, Sign In to add comment