We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Friday, June 12, 2015

Write a program Convert to number to binary


class Program

{

    static void Main(string[] args)

    {

        int num, temp = 1, n = 0;

        Console.Write("Enter a Number : ");

        num = int.Parse(Console.ReadLine());


        while (num > 0)

        {

            if (num % 2 == 1)

                n = n + temp;

            num = num / 2;

            temp = temp * 10;

        }


        Console.WriteLine("The Binary format for given number is: {0}", n);

        Console.ReadLine();


    }


}



No comments: