C# Program to convert Decimal to Binary
Example:
using System;
public class DecimalToBinary
{
public static void Main(string[] args)
{
int number, i;
int[] arr = new int[10];
Console.Write("Enter any Decimal Number: ");
number= int.Parse(Console.ReadLine());
for(i=0; number>0; i++)
{
arr[i] = number%2;
number = number/2;
}
Console.Write("\nBinary: ");
for(i=i-1 ;i>=0 ;i--)
{
Console.Write(arr[i]);
}
}
}
Output:
Enter any Decimal Number: 123 Binary: 1111011
Share this page on:
Subscribe Email Updates
to get latest update