Implement Recursive functions for binary to Decimal Conversion

All QuestionsCategory: C LanguageImplement Recursive functions for binary to Decimal Conversion
nikhil.d asked 3 years ago
2 Answers
nikhil.d answered 3 years ago

#include <stdio.h>
int binarytodecimal(int binarynum)
{
    if (!(binarynum / 10))
        return binarynum;
    return (binarynum % 10 + binarytodecimal(binarynum / 10) * 2);
}
int main()
{
    int binarynum;
    printf(“enter the binary number \n”);
    scanf(“%d”, &binarynum);
    printf(“equivalant decimal number is %d”, binarytodecimal(binarynum));
    return 0;
}

Anonymous answered 3 years ago

Note: Change the double inverted comma ( ” ) in the code to avoid an error.