Write a C# program to convert decimal number to binary.

 


using System;

public class DecimalToBinary
{
    public static void Main(string[] args)
    {
        int decimalNumber;
        string binaryNumber = "";

        // Get the decimal number from the user.
        Console.WriteLine("Enter a decimal number: ");
        decimalNumber = int.Parse(Console.ReadLine());

        // Convert the decimal number to binary.
        while (decimalNumber > 0)
        {
            binaryNumber += (decimalNumber % 2).ToString();
            decimalNumber /= 2;
        }

        // Reverse the binary number.
        binaryNumber = binaryNumber.Substring(0, binaryNumber.Length - 1);

        // Print the binary number.
        Console.WriteLine("The binary number is: {0}", binaryNumber);
    }
}
Write a C# program to convert decimal number to binary. Write a C# program to convert decimal number to binary. Reviewed by Bhaumik Patel on 8:30 PM Rating: 5