title: converting from binary to decimal
body: <p>The code should convert binary numbers to decimal but it doesn't. Can anyone please check where I could have gone wrong.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  #include &lt;string.h&gt;
  
  int main()
  {
  
      char s[40];
      int base;
      int index,n,p,sum=0;     /* n is the number of digits in the converted value */
  
      printf("enter the number and base: ");
      scanf("%s %d",s,&amp;base);
  
      for(n=strlen(s)-1;n&gt;=0;n--)
      {
          p=strlen(s);
          for(index=strlen(s)-(p-1); index&lt;=p; index++)
          {
          sum += s[index] * pow(base,n);
          }
      }
      printf("decimal no. is %d",sum);
      printf("\n");
  
  }
  </code></pre>
  
  <p>output::</p>
  
  <pre><code>enter the number and base:1011
  2
  </code></pre>
  
  <p>decimal no. is 1487</p>