Q:

Write a C# program to Print Binary Equivalent of an Integer using Recursion

0

Write a C# program to Print Binary Equivalent of an Integer using Recursion

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

I have used Visual Studio 2012 for debugging purpose. But you can use any version of visul studio as per your availability..

using System;
 
class Program
{
    public static void Main(string[] args)
    {
        int num;
        program p = new program();
        Console.WriteLine("Enter a decimal number: ");
        num = int.Parse(Console.ReadLine());
        Console.Write("The binary equivalent of num is :");
        p.binaryconversion(num);
        Console.ReadLine();
    }
}
public class program
{
    public int binaryconversion(int num)
    {
        int bin;
        if (num != 0)
        {
            bin = (num % 2) + 10 * binaryconversion(num / 2);
            Console.Write(bin);
            return 0;
        }
        else
        {
            return 0;
        }
 
    }
}

Result:

Enter a decimal number: 

9

The binary equivalent of num is :1001

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a C# program to create a recursive function ... >>
<< Write a C# program to create a function to display...