title: c program for binary to decimal conversion
body: <p>Please help me to sort out the error in the following program.I am not getting the correct output for the decimal part.
  Thanks in advance</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;math.h&gt;
  
  main()
  {
      int p,i,j,t,x;
      float n,sum,d;
  
      printf("enter the binary number");
      scanf("%f",&amp;n);
  
      p=(int)n;
      d=n-p;
  
      i=0;
      while(p&gt;0)
      {
          t=p%10;
          sum=sum+t*pow(2,i);
          p=p/10;
          i=i+1;
      }
  
      i=1;
      while(d&gt;0.0)
      {
          d=d*10;
          x=(int)d;
          sum=sum+x*pow(2,-i);
          d=d-x;
          i=i+1;
      }
  
      printf("decimal value is %f",sum);
      getch();
  }
  </code></pre>