// Write a program to print the binary format of a number
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
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;
}
// Reversing the value
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();
}
}
}
Sunday, 10 February 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment