#include <iostream>
usingnamespace std;
int main()
{
int a;
int b = 0;
cout << " Enter a number : ";
cin >> a;
while ( a > 0 ) {
b =b+ a % 10;
a= a/ 10;
}
cout << "Sum = " << b;
return 0;
}
if I write in 155 I do not get why I have the output 11.
because b=b+a%10= 0+155%10=5
5=5+150/10=5+15=20
I know that code is right but I do not get the logic can someone explain it for me in details??