对于任意输入的5位整数,计算其各个数位上的数字之和。
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream> using namespace std; int main() { int sum=0,n,i=1; cout<<"input a number:"; cin>>n; while(i<=5){ sum=sum+n%10; n=n/10; i++; } cout<<sum; }
edit & run
Username or Email Address
Password
Remember Me
Username
Email
Registration confirmation will be emailed to you.