plzz help me out ………..

Home Forums C Programming plzz help me out ………..

This topic contains 3 replies, has 2 voices, and was last updated by  DeenaDeBernales 9 years, 9 months ago.

  • Author
    Posts
  • #2240

    I need a source code in c that converts binary fraction to decimal fraction without using array or pointer.
    for example if i give input value .1101 i will get .8125

  • #3636

    Could do this:

  • #3637

    #include
    #include
    //#include

    void main()
    {
    float bin;
    float dec=0,multiplier=.5;
    int temp,i=1,p; clrscr();
    printf(“ENTER ANY BINARY NUMBER: “);
    scanf(“%f”,&bin);
    while(bin>0.0)
    {
    temp=(bin*10);

    printf(“%dn”,temp);
    bin=bin*10;
    printf(“%fn”,bin);
    bin=bin-temp;
    printf(“nbin=%fn”,bin);
    // p=pow(2,i);

    dec=(dec+(multiplier*temp));
    multiplier=multiplier*.5;
    }
    printf(“nnnTHE EQUIVALENT DECIMAL NUMBER IS: %f”,dec);
    getch();
    }

    I have written this code btt this is not working.. for example suppose if i take .11 then after 2 nd time rotation of while loop the value of bin becomes 0.000000 bt when it goes to check with while loop that is (0.000000>0)it evalutes true ………which is not desired ……..how can i overcome this …………………..

  • #3638

    #include
    #include
    //#include

    void main()
    {
    float bin;
    float dec=0,multiplier=.5;
    int temp,i=1,p; clrscr();
    printf(“ENTER ANY BINARY NUMBER: “);
    scanf(“%f”,&bin);
    while(bin>0.0)
    {
    temp=(bin*10);

    printf(“%dn”,temp);
    bin=bin*10;
    printf(“%fn”,bin);
    bin=bin-temp;
    printf(“nbin=%fn”,bin);
    // p=pow(2,i);

    dec=(dec+(multiplier*temp));
    multiplier=multiplier*.5;
    }
    printf(“nnnTHE EQUIVALENT DECIMAL NUMBER IS: %f”,dec);
    getch();
    }

    I have written this code btt this is not working.. for example suppose if i take .11 then after 2 nd time rotation of while loop the value of bin becomes 0.000000 bt when it goes to check with while loop that is (0.000000>0)it evalutes true ………which is not desired ……..how can i overcome this …………………..

You must be logged in to reply to this topic.

Share
Tweet
Share
Pin