Saturday 2 December 2017

C# Program to Convert Decimal to Binary


Code:

using System;
class myclass
{
    static void Main()
    {
        int num;
        Console.Write("Enter a Number : ");
        num = int.Parse(Console.ReadLine());
        int quot;
        string rem = "";
        while (num >= 1)
        {
            quot = num / 2;
            rem += (num % 2).ToString();
            num = quot;
        }
        string bin = "";
        for (int i = rem.Length - 1; i >= 0; i--)
        {
            bin = bin + rem[i];
        }
        Console.WriteLine("The Binary format for given number is {0}", bin);
        Console.Read();
    }
}


Output:

Enter the Number : 3
Binary Format for the Given Number is : 11


More C# Programs:
















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...