摘一朵水仙花数

时间:2021-12-29 16:17:09

  在数论中,水仙花数Narcissistic number[1][2],也被称为超完全数字不变数pluperfect digital invariant, PPDI[3]自恋数自幂数阿姆斯壮数阿姆斯特朗数Armstrong number[4] ,用来描述一个N位非负整数,其各个位数字的N次方和等于该数本身。

以上摘自 * 

 

  Code by C language :

 

//水仙花数1,用来描述一个N位非负整数,其各个位数字的N次方和等于该数本身
//日期:2014-1-8
#include<stdio.h>
#include
<stdlib.h>
#include
<math.h>
int main()
{
int number;
int number_bit , i , j=1 ,k;
int number_cal , number_check = 0;
//for(k=0;k<99;k++)
while(1)
{
printf(
"****************************************\nplease input a number :");
scanf(
"%d",&number);
//number=k;
number_cal = number_bit=number;
number_check
= 0;
if(number <0 )
{
printf(
"the number you input is not a Daffodils .\n");
exit(
1);
}
for(i=0,j=1;number_bit>=10;i++,j++)
{
number_bit
=number_bit/10;
}
printf(
"\nthe number you input has %d bit(s) , ",j);
for(i=0;i<j;i++)
{
int temp;
temp
=number_cal%10;
number_check
=number_check+pow(temp,j);
number_cal
/=10;
}
if(number_check==number)
printf(
"is a Daffodils .");
else
printf(
"is not a Daffodils .");
printf(
"\n\n");
}
return 0;
}

 

  Result view :

 摘一朵水仙花数