-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnarcissistic-number.c
51 lines (41 loc) · 3.04 KB
/
narcissistic-number.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
void main()
{
int num, rem, i, temp = 0;
int cub_num = 0;
int quo;
printf("Enter a number: ");
scanf("%d", &num);
printf("\n");
temp = num;
while (temp>=10)
{
rem = temp % 10;
printf("Remainder value: %d\n", rem);
quo = temp / 10;
printf("Quotient value: %d\n", quo);
cub_num += rem*rem*rem*rem;
printf("%d^4 value: %d\n", rem, cub_num);
temp = quo;
}
cub_num += temp*temp*temp*temp;
printf("%d^4 value: %d\n\n", temp, cub_num);
if (cub_num == num)
printf("%d == %d, %d is a Narcissistic number", num, cub_num, num);
else
printf("%d != %d, %d is not a Narcissistic number", num, cub_num, num);
}
/* Output:
Enter a number: 9474
Remainder value: 4
Quotient value: 947
4^4 value: 256
Remainder value: 7
Quotient value: 94
7^4 value: 2657
Remainder value: 4
Quotient value: 9
4^4 value: 2913
9^4 value: 9474
9474 == 9474, 9474 is a Narcissistic number
*/