水仙花数

#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;

bool Narcissistic_number(int n){
    int t=n;
    int a[3];
    int k=0;
    while(t>0){         //提取每一位的数字 
        a[k]=t%10;
        t=t/10;
        k++;
    }
    if((a[0]*a[0]*a[0]+a[1]*a[1]*a[1]+a[2]*a[2]*a[2])==n) return true;
    else return false;
}

int main(){
    int a;
    cin>>a;
    cout<<Narcissistic_number(a);
    return 0;
} 

 

posted @ 2021-01-10 21:54  Maxwell·  阅读(37)  评论(0编辑  收藏  举报