//Program to print sum of digits
#include <iostream>
using namespace std;
int main()
{
    int n, m, sum = 0;
    cin >> n;             
   for(int i = 0; i < n; i++)
    {
        m = n % 10;     
        sum += m;      
        n = n / 10;    
    }
    cout << sum;
}
    //Outputs
    
   // Input = 123
   // Output = 5 (should be 6)
    
   // Input = 0235
   // Ouput = 8 (should be 9)
Not printing the right answer when input no. is starting from 1 or 0.
By using While (n>0), it's giving the right output but I can't figure out why?
 
    