找出100-999之间(含100和999)所有整数中各位上数字之和为X(X为一个正整数)的整数,然后按每行5个数输

2024-12-20 06:28:17
推荐回答(2个)
回答1:

int SpSum(int v)
{
int s = 0;
if(v <= 0)
throw ...
while(v > 0)
{
s += mod(v, 10);
v = v%10;
}
return v;
}
void EnumNum(int min, int max, int x)
{
if(min <=0 || max <= 0 || min >= max)
throw ...
for(int i = min; i <= max; i++)
if(SpSum(i) == x)
cout << i << endl;
}
试试看对不对

回答2:

x=int(input())
k=0
for i in range(100,1000):
if(x==i//100+i%10+i%100//10):
print(i,' ')
k+=1
if(k==4):
k=0
print()