-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoran_number.c
More file actions
59 lines (51 loc) · 1.01 KB
/
moran_number.c
File metadata and controls
59 lines (51 loc) · 1.01 KB
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
52
53
54
55
56
57
58
59
#include <stdio.h>
int main()
{
int n;
printf("Enter a number: ");
scanf("%d", &n);
if (n <= 0)
{
printf("Invalid input. Please enter a positive number.\n");
return 1;
}
int sum = 0, temp = n, quo;
int primeno = 1;
while (temp != 0)
{
sum += temp % 10;
temp /= 10;
}
if (n % sum == 0)
{
quo = n / sum;
if (quo < 2)
{
primeno = 0;
}
else
{
for (int i = 2; i <= quo / 2; i++)
{
if (quo % i == 0)
{
primeno = 0;
break;
}
}
}
if (primeno)
{
printf("Yes, it is a Moran number\n");
}
else
{
printf("No, it is not a Moran number\n");
}
}
else
{
printf("No, it is not a Moran number\n");
}
return 0;
}