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
- 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.
- Program in C and C++ to Convert Decimal to Binary number Using recursive function
0 Comments