adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in C and C++ to Convert Decimal to Binary number Using recursive function

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

Post a Comment

0 Comments