给定程序中,函数fun的功能是:找出100-999之间所有整数中各位上数字之和为x(x为一整数)的整数,然后输出:符合条件的整数个数作为函数返回值。
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int fun(int x)
{
int n, s1, s2, s3, t;
n = 0;
t = 100;
while (t <= 999)
{
s1 = t % 10;
s2 = (t / 10) % 10;
s3 = t / 100;
if (s1 + s2 + s3 == x)
{
printf(" %d ", t);
n++;
}
t++;
}
return n;
}
int main()
{
int x = -1;
while (x < 0)
{
printf("Please input(x>0):");
scanf("%d", &x);
}
printf("\nThe result is :%d\n", fun(x));
getchar();
getchar();
return 0;
}