title: Program in C to sum each digit in an integer
body: <pre><code>int main(){
      int x;
      int sum;
  
      printf("Enter a positive integer: ");
      scanf("%d", &amp;x);
  
      do{
  
          sum += (x%10);
          x=(x/10);
  
          if((x/10)==0){
              sum += x;
          }
      }
      while((x/10)!=0);
  
      printf("%d",sum);
  }
  </code></pre>
  
  <p>Hey, I'm trying to get this to add up each digit within the entered integer, but the code I'm using keeps returning the wrong output. Would someone please help me fix my equation/code, because I'm not sure why the output is incorrect.</p>