#include
using namespace std;
int main(){
cout<<"请输入一个整数"<int num;
cin>>num;
cout<<"你输入的数字是:"<void sumandnum(int num);
sumandnum(num);
return 0;
}
void sumandnum(int num){
if(num==0) cout<<"位数是1,各位数字之和为0"<if(num<0) num=-num;
static int count=0;
static int sum=0;
while(num){
sum+=num%10;
num/=10;
++count;
}
cout<<"位数是"<}
思路给你
用这个数字来除以10
do{b++;a=a/10;}while(a>=10)
这样算位数
各位数字之和
就这样
do{
sum+=a%10;
a=a/10;}while(a>=10)
#include "stdio.h"
void main()
{
int a,b=0,c=0;
scanf("%d",&a);
if (a<0)
a=-a;
for (;a>0;)
{
b++;
c+=a%10;
a/=10;
}
printf("count =%d,",b);
printf("sum =%d",c);
}