Problem while solving Sum of Digits Problem Code: FLOW006

Hi,
I am trying to solve this simple problem. It’s working well but not sure why failing with some of the test case:

#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	while(cin >> n){
		int sum = 0;
		while(n > 0){
			sum += n%10 ;
	 		n /=10;
		}
		cout <<sum<<endl;
	}
		
}

Can someone have a look and guide me?

This is not how you’re reading in the input :slight_smile: Note that it gives the wrong output even for the Example Input.

1 Like