#30987: c 解法參考


judgeking001 (adking)

學校 : 不指定學校
編號 : 195281
來源 : [220.143.68.215]
最後登入時間 :
2024-03-06 14:17:19
a040. 阿姆斯壯數 | From: [180.218.90.34] | 發表日期 : 2022-06-30 11:20

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

int ans_pow(int n,int m){   //先算幾位數(幾次方(count)),把每一位數的count次方算出來再相加 
    int temp_1=1,temp_2=0,a=0,b,count=0;
    while(m){
        m/=10;
        count++;        
    }
    while(n>0){
    b=n%10;
    for(a=0;a<count;a++){        
        temp_1*=b;        
    }
    n/=10;        
    temp_2+=temp_1;
    temp_1=1;
}
    return temp_2;    
}

int main(){
    int min,max,i,ans,plus=0;
    scanf("%d %d",&min,&max);
    for(i=min;i<=max;i++){
        ans=ans_pow(i,i);
        if(ans==i){
        printf("%d ",i);
        plus++;
    }
        else
        continue;                
    }
    if(plus==0)
    printf("none");    
    return 0;
}

 
ZeroJudge Forum