background image

    int len=0;
    do
    {
        ++len;
        m=m/10;
    }while(m); 
    return len;
}

void judgeEqual(int m,int n)
{/*parameter m is a integer,parameter n is the digit of m,this function is used to judge m whether 
is a Armstrong integer and output it*/
    int j,temp=m,sum=0;
    for(j=1;j<=n;j++)
    {
        sum+=(int)(pow(temp%10,n));
        temp=temp/10;
    }
    if(m==sum)/*if m is equal to sum,that is to say m is a Armstrong integer*/
        printf("%d\t",m);
}
 
【程序输入输出】
no input;
output:
All 2 digit to 5 digit Armstrong integers are following:
153    370     371     407     1634    8208    9474    54748   92727   93084
注:用 gcc 调试就得不到 153 这个结果,但 windows 下用 vc6.0 就可以得到。不解中,这是
编译器问题还是程序问题?
3、

【问题描述】将 1,2,3,4,5,6,7,8,9 共 9 个数分成三组,组成 3 个三位数,且使这 3 个三位数构成

1:2:3 的比例,例如:3 个三位数 192,384,576 满足以上条件.192:384:576=1:2:3。试求出所有满
足条件的 3 个三位数。

【思路】1~9 组成的最小三位数是 123,最大的是 987,由于要满足 1:2:3 的关系,最小

的那个数应该不到于 987/3=329。这样的话第一个数的变化范围是 123~329,将这里面的
数分别乘 2、乘 3,然后判断这三个数是否符合要求,即这三个数是否由 1~9 组成,而且
各个数字不能相同。
     即对每个数 n(123<=n<=329)用枚举法。

定义函数 int judge(int n),用于判断整数 n 的各位数字是否相同,如果有想同的就返回 0;
否则返回 1;
对每个数 n(123<=n<=329),2*n,3*n 调用 judge()函数用于判断这三个数是否由 1~9 组成
且各个数字不相同;