dabentudou 于 2016.01.15 22:39 提问

11个回答

caozhy      2016.01.15 22:40

caozhy      2016.01.15 22:41
CSDNXIAOD   2016.01.15 22:41

----------------------biu~biu~biu~~~在下问答机器人小D，这是我依靠自己的聪明才智给出的答案，如果不正确，你来咬我啊！

u012374972   2016.01.16 02:34

#include
#include
#include
#include
#include

#define P(X) printf("Is "#X" a shui_xian_hua_shu?\n")

unsigned long int cubic(unsigned long int n,unsigned int a);
void divnum(unsigned int *num, unsigned int *one, unsigned int *two, unsigned int *three, unsigned int *four, unsigned int *five, unsigned int *six, unsigned int *seven, unsigned int *eight, unsigned int *nine, unsigned int *ten);

void main()
{
unsigned long int num=0;

unsigned int one, two, three, four, five, six, seven, eight, nine, ten;

`````` unsigned int i=0;

scanf("%ld", &num);

divnum(&num, &one, &two, &three, &four, &five, &six, &seven, &eight, &nine, &ten);
P(num);
if (num == cubic(num, one) + cubic(num, two) + cubic(num, three) + cubic(num, four) + cubic(num, five) + cubic(num, six) + cubic(num, seven) + cubic(num, eight) + cubic(num, nine) + cubic(num, ten))
{
printf("yes\n");
}
else
{
printf("no\n");
}*/

printf("--------------------------------------------------\n");
printf("There are the whole narcissistic number:\n");
num = 1;
for (num = 1; num <= 4294967295; num++)
{
divnum(&num, &one, &two, &three, &four, &five, &six, &seven, &eight, &nine, &ten);
if (num == cubic(num, one) + cubic(num, two) + cubic(num, three) + cubic(num, four) + cubic(num, five) + cubic(num, six) + cubic(num, seven) + cubic(num, eight) + cubic(num, nine) + cubic(num, ten))
{
printf("%lu\n",num);
}
else
{
continue;
}
}

_getch();
``````

}

unsigned long int cubic(unsigned int n,unsigned long int a)
{
if (n>=1 && n<=9)
return a;
if (n >= 10 && n<=99)
return a*a;
if (n >= 100 && n <= 999)
return a*a*a;
if (n >= 1000 && n<=9999)
return a*a*a*a;
if (n >= 10000 && n<=99999)
return a*a*a*a*a;
if (n >= 100000 && n<=999999)
return a*a*a*a*a*a;
if (n >= 1000000 && n<=9999999)
return a*a*a*a*a*a*a;
if (n >= 10000000 && n<=99999999)
return a*a*a*a*a*a*a*a;
if (n >= 100000000 && n<=999999999)
return a*a*a*a*a*a*a*a*a;
if (n >= 1000000000 && n<=9999999999)
return a*a*a*a*a*a*a*a*a*a;
}

void divnum(unsigned int *num, unsigned int *one, unsigned int *two, unsigned int *three, unsigned int *four, unsigned int *five, unsigned int *six, unsigned int *seven, unsigned int *eight, unsigned int *nine, unsigned int *ten)
{
*one = *num / 1000000000;
*two = (*num - *one * 1000000000) / 100000000;
*three = (*num - *one * 1000000000 - *two * 100000000) / 10000000;
*four = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000) / 1000000;
*five = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000) / 100000;
*six = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000) / 10000;
*seven = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000) / 1000;
*eight = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000 - *seven * 1000) / 100;
*nine = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000 - *seven * 1000 - *eight * 100) / 10;
*ten = *num % 10;
}

FGF_C 3位数 逗

u012374972   2016.01.16 02:38

#include
#include
#include
#include
#include

#define P(X) printf("Is "#X" a shui_xian_hua_shu?\n")

unsigned long int cubic(unsigned long int n,unsigned int a);
void divnum(unsigned int *num, unsigned int *one, unsigned int *two, unsigned int *three, unsigned int *four, unsigned int *five, unsigned int *six, unsigned int *seven, unsigned int *eight, unsigned int *nine, unsigned int *ten);

void main()
{
unsigned long int num=0;

unsigned int one, two, three, four, five, six, seven, eight, nine, ten;

`````` unsigned int i=0;

scanf("%ld", &num);

divnum(&num, &one, &two, &three, &four, &five, &six, &seven, &eight, &nine, &ten);
P(num);
if (num == cubic(num, one) + cubic(num, two) + cubic(num, three) + cubic(num, four) + cubic(num, five) + cubic(num, six) + cubic(num, seven) + cubic(num, eight) + cubic(num, nine) + cubic(num, ten))
{
printf("yes\n");
}
else
{
printf("no\n");
}*/

printf("--------------------------------------------------\n");
printf("There are the whole narcissistic number:\n");
num = 1;
for (num = 1; num <= 4294967295; num++)
{
divnum(&num, &one, &two, &three, &four, &five, &six, &seven, &eight, &nine, &ten);
if (num == cubic(num, one) + cubic(num, two) + cubic(num, three) + cubic(num, four) + cubic(num, five) + cubic(num, six) + cubic(num, seven) + cubic(num, eight) + cubic(num, nine) + cubic(num, ten))
{
printf("%lu\n",num);
}
else
{
continue;
}
}

_getch();
``````

}

unsigned long int cubic(unsigned int n,unsigned long int a)
{
if (n>=1 && n<=9)
return a;
if (n >= 10 && n<=99)
return a*a;
if (n >= 100 && n <= 999)
return a*a*a;
if (n >= 1000 && n<=9999)
return a*a*a*a;
if (n >= 10000 && n<=99999)
return a*a*a*a*a;
if (n >= 100000 && n<=999999)
return a*a*a*a*a*a;
if (n >= 1000000 && n<=9999999)
return a*a*a*a*a*a*a;
if (n >= 10000000 && n<=99999999)
return a*a*a*a*a*a*a*a;
if (n >= 100000000 && n<=999999999)
return a*a*a*a*a*a*a*a*a;
if (n >= 1000000000 && n<=9999999999)
return a*a*a*a*a*a*a*a*a*a;
}

void divnum(unsigned int *num, unsigned int *one, unsigned int *two, unsigned int *three, unsigned int *four, unsigned int *five, unsigned int *six, unsigned int *seven, unsigned int *eight, unsigned int *nine, unsigned int *ten)
{
*one = *num / 1000000000;
*two = (*num - *one * 1000000000) / 100000000;
*three = (*num - *one * 1000000000 - *two * 100000000) / 10000000;
*four = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000) / 1000000;
*five = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000) / 100000;
*six = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000) / 10000;
*seven = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000) / 1000;
*eight = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000 - *seven * 1000) / 100;
*nine = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000 - *seven * 1000 - *eight * 100) / 10;
*ten = *num % 10;
}

``````
``````
u012374972   2016.01.16 02:39
``````
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <complex.h>

#define P(X) printf("Is "#X"  a shui_xian_hua_shu?\n")

unsigned long int cubic(unsigned long int n,unsigned int a);
void divnum(unsigned int *num, unsigned int *one, unsigned int *two, unsigned int *three, unsigned int *four, unsigned int *five, unsigned int *six, unsigned int *seven, unsigned int *eight, unsigned int *nine, unsigned int *ten);

void main()
{
unsigned long int num=0;
unsigned int one, two, three, four, five, six, seven, eight, nine, ten;

unsigned int i=0;

scanf("%ld", &num);

divnum(&num, &one, &two, &three, &four, &five, &six, &seven, &eight, &nine, &ten);
P(num);
if (num == cubic(num, one) + cubic(num, two) + cubic(num, three) + cubic(num, four) + cubic(num, five) + cubic(num, six) + cubic(num, seven) + cubic(num, eight) + cubic(num, nine) + cubic(num, ten))
{
printf("yes\n");
}
else
{
printf("no\n");
}*/

printf("--------------------------------------------------\n");
printf("There are the whole narcissistic number:\n");
num = 1;
for (num = 1; num <= 4294967295; num++)
{
divnum(&num, &one, &two, &three, &four, &five, &six, &seven, &eight, &nine, &ten);
if (num == cubic(num, one) + cubic(num, two) + cubic(num, three) + cubic(num, four) + cubic(num, five) + cubic(num, six) + cubic(num, seven) + cubic(num, eight) + cubic(num, nine) + cubic(num, ten))
{
printf("%lu\n",num);
}
else
{
continue;
}
}

_getch();
}

unsigned long int cubic(unsigned int n,unsigned long int a)
{
if (n>=1 && n<=9)
return a;
if (n >= 10 && n<=99)
return a*a;
if (n >= 100 && n <= 999)
return a*a*a;
if (n >= 1000 && n<=9999)
return a*a*a*a;
if (n >= 10000 && n<=99999)
return a*a*a*a*a;
if (n >= 100000 && n<=999999)
return a*a*a*a*a*a;
if (n >= 1000000 && n<=9999999)
return a*a*a*a*a*a*a;
if (n >= 10000000 && n<=99999999)
return a*a*a*a*a*a*a*a;
if (n >= 100000000 && n<=999999999)
return a*a*a*a*a*a*a*a*a;
if (n >= 1000000000 && n<=9999999999)
return a*a*a*a*a*a*a*a*a*a;
}

void divnum(unsigned int *num, unsigned int *one, unsigned int *two, unsigned int *three, unsigned int *four, unsigned int *five, unsigned int *six, unsigned int *seven, unsigned int *eight, unsigned int *nine, unsigned int *ten)
{
*one = *num / 1000000000;
*two = (*num - *one * 1000000000) / 100000000;
*three = (*num - *one * 1000000000 - *two * 100000000) / 10000000;
*four = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000) / 1000000;
*five = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000) / 100000;
*six = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000) / 10000;
*seven = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000) / 1000;
*eight = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000 - *seven * 1000) / 100;
*nine = (*num - *one * 1000000000 - *two * 100000000 - *three * 10000000 - *four * 1000000 - *five * 100000 - *six * 10000 - *seven * 1000 - *eight * 100) / 10;
*ten = *num % 10;
}

``````
u012374972   2016.01.16 03:11
`````` //第一次评论，不怎么会插入代码^
``````
91program      2016.01.16 11:14

abcd_123457   2016.01.16 15:22
`````` //水仙花数是指一个 n 位数 ( n≥3 )，它的每个位上的数字的 n 次幂之和等于它本身
char NarcissisticNumber(unsigned long v)
{
char st = 0;
unsigned char n = 0;
unsigned long tval = 0;
unsigned long sum = 0;
if(v < 100)
return st;
//计算数据位数。
tval = v;
do
{
if(tval != 0)
n++;
tval /= 10;
} while (tval != 0);
//计算每一位的n次方
tval = v;
do
{
sum += pow(tval % 10,n);
tval /= 10;
} while (tval != 0);

//返回结果 0表示不是水仙花数，1表示是水仙花数
if(sum == v)
st = 1;
return st;
}

``````
qq_27183003      2016.01.16 22:30

``````#include <stdio.h>
void fun(int n)
{
if(n<100 || n>1000) return;
int a,b,c;
c=n%10;
b=n/10%10;
a=n/100%10;
if(a*a*a+b*b*b+c*c*c == n) printf("%d\n",n);
fun(n+1);
}
void main()
{
fun(100);
}
``````