Denary to binary
Sign in to test your solution.
// Denary to binary program
using System;
class Submission
{
// -------------------------
// Subprograms
// -------------------------
static string den_to_bin(int number)
{
string binary = "";
while (number > 0)
{
int remainder = number % 2;
binary = Convert.ToString(remainder) + binary;
number = number / 2;
}
return binary;
}
// -------------------------
// Main program
// -------------------------
public static void Main(string[] args)
{
Console.WriteLine("Enter the denary number to convert:");
int number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Binary: " + den_to_bin(number));
}
}
You can submit as many times as you like. Only your latest submission will be taken into account.
Sign in to test your solution.