#25780: C language 簡易寫法


22207807 (會打Code的貓)

學校 : 逢甲大學
編號 : 156777
來源 : [140.134.241.201]
最後登入時間 :
2023-03-14 12:33:09
a040. 阿姆斯壯數 | From: [42.72.17.218] | 發表日期 : 2021-06-22 11:40

#include<stdio.h>

#include<math.h>

int main () {

int m,n,p;

int carry,tem,num,judge=0;

scanf("%d %d",&n,&m);

for(int i = n; i <= m; i++) {

carry = 1;

tem = i;

while( tem / 10 != 0) {

carry ++;

tem /= 10;

}

tem = i;

for(int j = carry - 1; j >=0 ; j--) {

p = pow(10,j);

num += pow((tem / p),carry);

tem %= p;

}

if(i == num) {

judge ++;

printf("%d ",num);

}

num = 0;

}

if(judge == 0)

printf("none");

return 0;

}

先算出該數有幾位數,再依序從最高位到最低位求個別的值並相加,最後判斷此範圍中是否有此數,有則印出,否則印出none

 
ZeroJudge Forum