In this C# tutorial we are "converting any decimal number entered by the user to binary" . Here we are taking four variables "num" for number ,"i" for counter ,"rem" for remainder and "z" for output respectively. Now, lets get started!!
using System; class conv { public static void Main(String []args) { int num,i=1,rem,z=0; Console.WriteLine("Please enter any decimal number : "); num=Convert.ToInt32(Console.ReadLine()); while(num!=0) { rem=num%2; num=num/2; z=z+rem*i; i=i*10; } Console.WriteLine(z); } }
0 comments:
Post a Comment