0

Write a program to enter any number from user and convert into Binary number e.g we enter 10 and his answer display 1010

can you help me please??? I'm very troubling in coding to write a program in C#

25th Feb 2017, 11:46 AM
Aftab ali
Aftab ali - avatar
2 Respuestas
+ 11
using System; namespace ToBin { class Program { static public string ToBinary(int num) { string result = ""; if (num == 0) return "0"; while ( num != 0 ) { result = num % 2 + result; num = num / 2; } return result; } static void Main(string[] args) { int number = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(ToBinary(number)); } } } --------------------------------- or just use the built in Convert.ToString( your_number, base=2 ). Check here for full details: https://msdn.microsoft.com/en-us/library/8s62fh68(v=vs.110).aspx
25th Feb 2017, 12:21 PM
Nikolay Nachev
Nikolay Nachev - avatar
0
thank you very much Sir Nikolay Nachec💝💝💝💝
25th Feb 2017, 2:09 PM
Aftab ali
Aftab ali - avatar