sum of digits

Description:

Write a c++ program to find the sum of digits of the given number Test Case 1 Input (stdin) 1234 Expected Output The sum is 10 Test Case 2 Input (stdin) 367 Expected Output The sum is 16

Program :

#include <iostream>

using namespace std;

int main()

{

int n,sum=0;

  cin>>n;

  while(n!=0)

  {

  sum=sum+n%10;

  n=n/10;

  }

  cout<<"The sum is "<<sum;

return 0;

}