A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C# Sharp program that takes a decimal number as input and displays its equivalent in binary form
Q:

Write a C# Sharp program that takes a decimal number as input and displays its equivalent in binary form

0

Write a C# Sharp program that takes a decimal number as input and displays its equivalent in binary form

Sample Output:

Input a Number : 65                                                                                           
Binary: 1000001

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public class Exercise11
{
  public static void Main()
  {   
    string answer;  
    string result; 
  
         Console.Write("Input a Number : ");
        answer = Console.ReadLine();
         
            int num = Convert.ToInt32(answer);
            result = "";
            while (num > 1)
            {
                int remainder = num % 2;
                result = Convert.ToString(remainder) + result;
                num /= 2;
            }
            result = Convert.ToString(num) + result;
            Console.WriteLine("Binary: {0}", result);
        }
   }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now