找出100-999之间(含100和999)所有整数中各位上数字之和为x(x为一正整数)的整数,然后输出;符合条件的整数个数作为函数值返回。
#include<stdio.h>
int fun(int x){
int n,s1,s2,s3,t;
n=0;
t=100;
/**********found*********/
while(t<=999) {
/**********found********/
s1=t%10;
s2=(t/10)%10;
s3=t/100;
/**********found********/
if(s1+s2+s3==x) {
printf("%d ",t);
n++;
}
t++;
}
return n;
}
void main() {
int x=-1;
while(x<0) {
scanf("%d",&x);
}
printf("%d",fun(x));
}