Please write a program for Decimal to Binary Conversion in c# ?

Total Post:25

Points:175
C#  OOPS 
C#
 239  View(s)
Ratings:
Rate this:

 Decimal to Binary Conversion in c# 

1------------------ 0

2 ------------------10

3 -------------------11

4------------------- 100

5 ---------------------101

6---------------------- 110

7 -----------------------111

8 -----------------------1000

9 -------------------------1001

10------------------------- 1010

  1. Post:46

    Points:324
    Re: Please write a program for Decimal to Binary Conversion in c# ?

    Decimal To Binary Conversion in c#

    using System; 
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ConsoleApplication30
    {
        class Program
        {
            static void Main(string[] args)
            {
                int n, i;
                int[] a = new int[10];
                Console.Write("Enter the number to convert: ");
                n = int.Parse(Console.ReadLine());
                for (i = 0; n > 0; i++)
                {
                    a[i] = n % 2;
                    n = n / 2;
                }
                Console.Write("\nBinary of the given number= ");
                for (i = i - 1; i >= 0; i--)
                {
                    Console.Write(a[i]);
                }
                Console.WriteLine("\n");
            }
        }
    }

    Please write a program for Decimal to Binary Conversion in c# ?

    Thank You...!!

Answer