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


Introduction

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


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. using System;
  2.  
  3. class Program
  4. {
  5. public static void Main(string[] args)
  6. {
  7. int num;
  8. program p = new program();
  9. Console.WriteLine("Enter a decimal number: ");
  10. num = int.Parse(Console.ReadLine());
  11. Console.Write("The binary equivalent of num is :");
  12. p.binaryconversion(num);
  13. Console.ReadLine();
  14. }
  15. }
  16. public class program
  17. {
  18. public int binaryconversion(int num)
  19. {
  20. int bin;
  21. if (num != 0)
  22. {
  23. bin = (num % 2) + 10 * binaryconversion(num / 2);
  24. Console.Write(bin);
  25. return 0;
  26. }
  27. else
  28. {
  29. return 0;
  30. }
  31.  
  32. }
  33. }

Result

C# language techstudy

     





Related Topics




Popular Posts