给定程序中,函数fun功能是:找出100~999之间
给定程序中,函数fun功能是:找出100~999之间(含100和999)所有整数中各位上数字之和为x(x为一正整数)的整数。然后输出:符合条件的整数个数作为函数值返回。
例如,当×值为5时,100~999之间各位上数字之和 5的整数有:104、113、122、131、140、203、212、221、230、302、311、320、401、410、500.共有15个。当x值为27时,各位数字之和为27的整数是:999。只有1个。
请在程序的下划线处填入正确的内容并把下划线删除。使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLAIK1.C中。
不得增行或删行,也不得更改程序的结构!
/*************code.c***********/
#include <stdio.h>
int fun(int x)
{
int n,s1,s2,s3,t;
n=0;
t=100;
while(t<=_____①_____)
{
s1=t%10;
s2=(_____②______)%10;
s3=t/100;
if(s1+s2+s3==_____③_____)
{
printf("%d",t);
n++;
}
t++;
}
return n;
}
void main()
{
int x=-1;
while(x<0)
{
printf("Please input(x>0):");
scanf("%d",&x);
}
printf("\nThe result is: %d\n",fun(x));
}答案
第1空:999
第2空:t/10
第3空:x