Program in C and C++ to Convert Decimal to Binary number Using recursive function
C Program
#include<stdio.h> void decToBin(int n){ if(n == 0) return; decToBin(n / 2); printf("%d",n % 2); } int main(){ int n; printf("Enter decimal number :- "); scanf("%d",&n); printf("Binary : "); decToBin(n); return; }
C++ Program
#include<iostream> using namespace std; void decToBin(int n){ if(n == 0) return; decToBin(n / 2); cout<<n % 2; } int main(){ int n; cout<<"Enter a decimal number :- "; cin>>n; cout<<"Binary : "; decToBin(n); return 0; }
Output :-
Related Programs
- Program in C & C++ to print the binary equivalent 1 to nth number.
- Program in C++ to Convert Binary to Decimal number Using Function
- Program in C to convert decimal into octal number.
- Program in C++ to Convert Hexadecimal to Decimal number Using Function
- Program in C++ to Convert Decimal to Hexadecimal number Using Function
- Program in C to Convert Decimal to Binary number.
- Program in C to print the binary equivalent 1 to nth number.
0 Comments