#include <iostream>
#include <cmath>
using namespace std;
int main() {
int N,S=0;
cin >> N;
N = abs(N);
while (N > 0) {
S += N % 10;
N /= 10;
}
cout << S;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int N,S=0;
cin >> N;
N = abs(N);
while (N > 0) {
S += N % 10;
N /= 10;
}
cout << S;
return 0;
}