Advertisement
sergezhu

Untitled

Apr 23rd, 2023
916
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. namespace ConsoleApp1;
  2.  
  3. using System.Text;
  4.  
  5. public class Task17
  6. {
  7.     public void Run()
  8.     {
  9.         Console.InputEncoding = Encoding.Unicode;
  10.         Console.OutputEncoding = Encoding.Unicode;
  11.  
  12.         Random random = new Random();
  13.         int includedLowBound = 1;
  14.         int excludedHighBound = 500;
  15.  
  16.         bool canExit = false;
  17.  
  18.         while ( canExit == false )
  19.         {
  20.             Console.Clear();
  21.  
  22.             int sourceNumber = random.Next( includedLowBound, excludedHighBound );
  23.  
  24.             int pow = 0;
  25.             int powerOfTwo = 1;
  26.  
  27.             while ( powerOfTwo <= sourceNumber )
  28.             {
  29.                 pow++;
  30.                 powerOfTwo *= 2;
  31.             }
  32.            
  33.             Console.WriteLine($"Source : {sourceNumber}, pow = {pow}, power of two = {powerOfTwo}");
  34.             Console.WriteLine();
  35.  
  36.             string properlyExitAnswer = "n";
  37.             Console.WriteLine( $"Continue? Enter \'{properlyExitAnswer}\' for exit" );
  38.             string continueAnswer = Console.ReadLine();
  39.  
  40.             canExit = string.Equals( continueAnswer, properlyExitAnswer );
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement