C# Program to Find Binary Equivalent of an Integer using Recursion Last Updated : 18 Oct, 2021 Comments Improve Suggest changes Like Article Like Report Given an integer number, now we convert the given integer number into a binary number using recursion. Recursion is a method in which a function calls itself directly or indirectly and such type of function is known as a recursive function. It solves the problem very efficiently like we find the binary equivalent of an integer. Examples: Input : 10 Output: 1010 Input : 11 Output: 1011Approach: To display the binary equivalent of an integer we use the following steps: If condition is used to check if the given value is not equal to zero.If the given condition is true then perform the modulus of the val by 2, then add the modulus result to 10 and then multiply the value of the result with the value of decimaltobinary() function.Now repeat step 2 until the value of val variable is greater than zero.Print the array in reverse order now.And if the condition is false then it will execute the else section, i.e., return 0The below image can help you better understand the approach. Let us considered the integer number is 10. Now we find the binary equivalent of 10 so, 10 % 2 + 10 * (10 / 2) % 2 will return 05 % 2 + 10 * (5 / 2) % 2 will return 12 % 2 + 10 * (2 / 2) % 2 will return 01 % 2 + 10 * (1 / 2) % 2 will return 1So the final result is 1010. Example 1: C# // C# program to display the binary equivalent // of an integer using System; class GFG{ // Driver code public static void Main(string[] args) { // Input int num = 15; decimaltobinary(num); } // Function to display the binary equivalent // of an integer public static int decimaltobinary(int val) { int binary; if (val != 0) { binary = (val % 2) + 10 * decimaltobinary(val / 2); Console.Write(binary); return 0; } else { return 0; } } } Output1111Example 2: C# // C# program to display the binary equivalent // of an integer using System; class GFG{ // Function to display the binary equivalent // of an integer public static int decimaltobinary(int val) { int binary; if (val != 0) { binary = (val % 2) + 10 * decimaltobinary(val / 2); Console.Write(binary); return 0; } else { return 0; } } // Driver code public static void Main(string[] args) { int num; // Reading input from user Console.Write("Hi! Enter the number:"); num = int.Parse(Console.ReadLine()); decimaltobinary(num); } } Output: Hi! Enter the number:10 1010 Create Quiz Comment P pulamolusaimohan Follow 0 Improve P pulamolusaimohan Follow 0 Improve Article Tags : C# CSharp LINQ CSharp-programs Explore IntroductionC# Tutorial 2 min read Introduction to .NET Framework 6 min read C# .NET Framework (Basic Architecture and Component Stack) 6 min read C# Hello World 2 min read Common Language Runtime (CLR) in C# 4 min read FundamentalsC# Identifiers 2 min read Data Types in C# 6 min read C# Variables 4 min read C# Literals 5 min read Operators in C# 7 min read C# Keywords 5 min read Control StatementsC# Decision Making (if, if-else, if-else-if ladder, nested if, switch, nested switch) 5 min read C# Switch Statement 4 min read Loops in C# 4 min read C# Jump Statements (Break, Continue, Goto, Return and Throw) 4 min read OOP ConceptsClass and Objects in C# 4 min read Constructors in C# 5 min read C# Inheritance 3 min read Encapsulation in C# 2 min read C# Abstraction 4 min read MethodsMethods in C# 4 min read Method Overloading in C# 4 min read Method Parameters in C# 4 min read Method Overriding in C# 7 min read Anonymous Method in C# 2 min read ArraysArrays in C# 6 min read Jagged Arrays in C# 4 min read Array Class in C# 5 min read How to Sort an Array in C# | Array.Sort() Method Set - 1 8 min read How to find the rank of an array in C# 2 min read ArrayListArrayList in C# 6 min read ArrayList Class in C# 4 min read C# | Array vs ArrayList 2 min read StringStrings in C# 6 min read C# Verbatim String Literal - @ 5 min read C# String Class 9 min read C# StringBuilder 2 min read C# String vs StringBuilder 3 min read TupleC# Tuple 7 min read C# Tuple Class 3 min read C# ValueTuple 7 min read C# ValueTuple Struct 4 min read IndexersC# Indexers 5 min read C# Multidimensional Indexers 5 min read C# - Overloading of Indexers 3 min read Like