天天看點

每日一題:第九題

第九題:判斷一個數是否為"水仙花數",所謂"水仙花數"是指一個三位數其各位數字的立方和等于該數本身。

例如:371是一個"水仙花數",371=3^3+7^3+1^3.

#include"stdio.h"

void main()

{

    int i,j,k,n;

    printf("please input the n:\n");

    scanf("%d",&n);

    printf("\n");

    i=n/100;

    j=(n-100*i)/10;

    k=n%10;

    if(i*i*i+j*j*j+k*k*k==n)

            printf("the  %d  is  Narcissistic number!\n",n);

    else 

            printf("the  %d  is  not  Narcissistic number!\n",n);

每日一題:第九題

繼續閱讀