Write a C++ Program to Add Digits of Number using pointer. Test Case 1 Input (stdin) 23 Expected Output The sum of the digits of 23 is 5 Test Case 2 Input (stdin) 6474 Expected Output The sum of the digits of 6474 is 21
#include <iostream>
using namespace std;
int main()
{
int a,b=0,c=0,n;
cin>>a;
n=a;
while(a>0)
{
b=a%10;
c=c+b;
a=a/10;
}
cout<<"The sum of the digits of "<<n<<" is "<<c;
return 0;
}