Pure C language: recursive binary to decimal source sharing

  • 2020-04-02 02:03:25
  • OfStack


#include<stdio.h>
#include<math.h>
int change(int n,int *sum,int *m)//N is the NTH bit, and m is the total number of bits
{
    char c;
    if(c!='#')
    {
        *m=*m+1;
        change(n+1,sum,m);
    }
    if(c=='#')
    {
        return *sum=int(*sum+pow(2,*m-n));
    }
}
void main()
{
    char c;
    int n=0,*sum=0,*m=0;
    printf(" Please enter binary number (' #' Beginning and end) : ");
    scanf("%c",c);
    int t=change(n,*sum,*m);
    printf(" The converted decimal number is: %d",t);
}</math.h></stdio.h>

Related articles: