#include <iostream> using namespace std; int main() { int n = 0; //定义变量 int sum = 0; cin >> n; //循环把每一位拿出来 while (n > 0) { int ge = n % 10; sum += ge; n = n / 10; } cout << sum; system("pause"); return 0; }
#include <iostream> using namespace std; int main() { int n = 0; //定义变量 int sum = 0; cin >> n; //循环把每一位拿出来 while (n > 0) { int ge = n % 10; sum += ge; n = n / 10; } cout << sum; system("pause"); return 0; }