-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicClassification.c
More file actions
56 lines (50 loc) · 840 Bytes
/
basicClassification.c
File metadata and controls
56 lines (50 loc) · 840 Bytes
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
#include <stdio.h>
#include "NumClass.h"
//caluclate the factorial of a number - (a)
int factorial(int a){
if(a>1){
return a*factorial(a-1);
}
return 1;
}
//check if a number is a strong number
int isStrong(int x){
int sum = 0;
int num = x;
if(x==0){
return false;
}
while(x>0){
sum = sum + factorial(x%10);
x = x/10;
}
if(num == sum){
return true;
}
return false;
}
//check if x is a prime number
int isPrime(int x){
int isprime = true;
if(x < 1){
return false;
}
if(x == 1){
return true;
}
for(int i = 2; i < x; i+=1){
if(x%i == 0){
isprime = false;
}
}
return isprime;
}
/*
int main(){
for(int i = 0; i < 150; i+=1){
printf("%d: is strong? %d \n" ,i,isStrong(i));
printf("%d: is prime? %d \n" ,i,isPrime(i));
printf("------------------------\n");
}
return 0;
}*/