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 Binary to Decimal number Using recursive function

 Program in C and C++ to Convert Binary to Decimal number Using recursive function
C Program
#include<stdio.h>
 int binToDec(int bin){
    static int base = 1;
    if(bin == 0)
        return 0;
    return (( bin % 10 ) * ((base *= 2) / 2) +binToDec(bin / 10));
 }

 int main(){

    int bin;
    printf("Enter binary number :- ");
    scanf("%d",&bin);
    printf("Decimal : %d",binToDec(bin));
    return 0;
 }
C++ Program
    #include<iostream>
 using namespace std;
 int binToDec(int bin){
    static int base = 1;
    if(bin == 0)
        return 0;
    return (( bin % 10 ) * ((base *= 2) / 2) +binToDec(bin / 10));
 }

 int main(){

    int bin;
    cout<<"Enter binary number :- ";
    cin>>bin;
    cout<<"Decimal : "<<binToDec(bin);
    return 0;
 }
Output :-







Related Programs

Post a Comment

0 Comments