找出100至x(x≤999)之间各位上的数字之和为15的所有整数,然后输出;符合条件的整数个数作为函数值返回。

#include  
int fun(int  x)
{
    int  n, s1, s2, s3, t;

    n = 0;
    t = 100;

    while (t <= x)
    {
        s1 = t % 10;  s2 = (t / 10) % 10;  s3 = t / 100;
        if (s1 + s2 + s3 == 15)
        {
            printf("%d ", t);
            n++;
        }

        t++;
    }
    return n;
}
int main()
{
    int  x = -1;
    while (x > 999 || x < 100)
    {
        printf("Please input(100     }
    printf("\nThe result is: %d\n", fun(x));
    return 0;
}
 

你可能感兴趣的:(蓝桥杯,p2p,c++)