Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  saheb
Language: C/C++
Code:
#include<stdio.h>
#include<math.h>
#include<string.h>
int ubin2dec(int binary[], int i, int n)
{
    if(i==n-1) return binary[i]*pow(2,n-1);
    return binary[i]*pow(2,i)+ubin2dec(binary,i+1,n);
}
int main()
{
    int n,i=0,binary[100];
    printf("Enter the Binary Number: ");
    scanf("%d", &n);
    while(n)
    {
        int r=n%10; 
        binary[i++]=r;
        n/=10;
    }
    printf("\nEquivalent Decimal Number is: %d", ubin2dec(binary,0,i));
}
Comments: