#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[])
{
cout << "Enter a three-digit number: ";
string input;
cin >> input;
int sum = 0;
for (int i = 0; i < input.length(); ++i)
{
sum += (int)input[i] - 48;
}
cout << "The sum is: " << sum << endl;
return 0;
}
Comments
Leave a comment