c++的一道编程题,求大佬

c++
2024-10-30 10:38:28
推荐回答(2个)
回答1:

#include

using namespace std;

int main()

{ int x,b0,b1,b2,sum;

  cout<<"请输入输入一个三位数:"<

  cin>>x;

  b0=x%10;

  b2=x/100;

  b1=x/10%10;

  sum=b0+b1+b2;

  cout<

  return 0;

}

回答2:

#include
static int main()
{
int input,b0,b1,b2,sum;

b0=0;
b1=0;
b2=0;
sum=0;
input=0;
do{
prinf("input the number:");
scanf("%d",&input);
}while(!((input>99)&&(input<1000))) //确保为三位数
b0 = input % 10;
b1 = (input /10)%10;
b2 = input /100;
sum=b0+b1+b2;
printf("b0:%d",b0);
printf("b1:%d",b1);
printf("b2:%d",b2);
printf("sum:%d",sum);
}