background image

please input n:
5
there are 8 ways to climb up N steps stairs!

2、
【问题描述】Armstrong 数具有如下特征:一个 n 位数等于其个位数的 n 次方之和。如:
153=13+53+33
1634=14+64+34+44
找出 2、3、4、5 位的所有 Armstrong 数。
【思路】看到此题我第一反应是用枚举法,给定 m(10<=m<=99999),首先判断 m 的位数
n,然后判断它是否等于各位数的 n 次方之和。
定义函数 int judgeDigit(int m),用于判断给定参数 m 的位数;
定义函数 int judgeEqual(int m,int n),其中 m 为给定的数,n 为 m 的位数,用于判断 m 是
否等于各位数的 n 次方之和。
【代码】
cCODE:
 

#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int judgeDigit(int m);
/*This function return the digit of parameter m*/

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 main (int argc, char **argv)
{
    int i,len;
    printf("All 2 digit to 5 digit Armstrong integers are following:\n");
    for(i=10;i<=99999;i++)
    {
        len=judgeDigit(i);
        judgeEqual(i,len);                
    }
    printf("\n");
    system("PAUSE");
    return 0;
}
int judgeDigit(int m)
{/*This function return the digit of parameter m*/