注册 登录
编程论坛 C语言论坛

小白问问题,大家帮帮忙鸭,求一个参考

twelvesion_ 发布于 2020-06-09 12:15, 1973 次点击
编写程序,统计输出所有五位整数中符合以下条件的数字个数:最高位数字和次高位数字的和是除最高位外的各位数字的积。要求使用数组。
3 回复
#2
rjsp2020-06-09 14:17
要求使用数组
不会,不理解。

程序代码:
#include <stdio.h>

int main( void )
{
    unsigned count = 1;
    for( unsigned b=1; b!=10; ++b )
    for( unsigned c=1; c!=10; ++c )
    for( unsigned d=1; d!=10; ++d )
    for( unsigned e=1; e!=10; ++e )
        count += b*c*d*e-b-1<9;

    printf( "%u\n", count );
}

#3
fulltimelink2020-06-09 14:23
程序代码:

#include <stdio.h>

int has0(int num) {
    int mul = 1;
    while (num / 10) {
        if(!(num % 10)) return 0;
        mul *= num % 10;
        num /= 10;
    }
    if (0 == num) return 0;
    return mul * num;
}

int main()
{
    int i5 = 1, i4 = 1, i3,mul3;
    for (; i4 < 10; i4++) {
        for (i3=111; i3 < 1000; i3++) {
            mul3 = has0(i3);
            if (!mul3) break;
            if (i4 * mul3 > 9)break;
            i5 = i4 * (mul3 - 1);
            // -- @# 最高位是否可为0
            
//if (0 == i5) continue;
            printf("%d%d%d\n", i5, i4, i3);
        }
    }
}
#4
ditg2020-06-09 15:04
程序代码:
#include <stdio.h>

void main(void)
{
    int a, b, c, d ,e;
    for (a = 1; a < 10; a++)
        for (b = 0; b < 10; b++)
            for (c = 0; c < 10; c++)
                for (d = 0; d < 10; d++)
                    for (e = 0; e < 10; e++)
                        if (a+b == b*c*d*e)
                            printf("%d\n", a*10000+b*1000+c*100+d*10+e);
}
1