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

Viewing 3 reply threads
  • Author
    Posts
    • #2240
      DeenaDeBernales
      Participant

      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
      GWILouisaxwzkla
      Participant

      Could do this:

    • #3637
      DeenaDeBernales
      Participant

      #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
      DeenaDeBernales
      Participant

      #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 …………………..

Viewing 3 reply threads
  • The forum ‘C Programming’ is closed to new topics and replies.