-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.c
114 lines (99 loc) · 1.82 KB
/
check.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//THAYCACAC
#include <stdio.h>
#include <math.h>
//HAM KIEM TRA SO NGUYEN TO
int isPrime(int n){
if(n<2) return 0;
for(int i=2; i<=sqrt(n); i++){
if(n%i==0) return 0;
}
return 1;
}
//HAM KIEM TRA SO CHINH PHUONG
int isSquare(int n){
if(n<2) return 0;
if(sqrt(n)==(int)sqrt(n)) return 1;
else return 0;
}
//HAM KIEM TRA SO HOAN HAO
int isPerfect(int n){
int s=0;
for(int i=1; i<n; i++){
if(n%i==0) s+=i;
}
if(n==s) return 1;
else return 0;
}
//HAM KIEM TRA SO PALINDROME
int isPalindrome(int n){
int sum=0,r;
int check=n;
while (n>0){
r=n%10;
sum=sum*10+r;
n/=10;
}
if(sum==check) return 1;
else return 0;
}
//HAM KIEM TRA SO CHIA HET CHO MOT SO X (VI DU CHIA HET CHO 7)
int isDivisible(int n){
if(n%7==0) return 1;
else return 0;
}
//HAM KIEM TRA 1/(2*N+1)<=C
void check1(double c){
int n=0;
while(1){
if(1.0/(2*n+1)<=c) break;
n++;
}
printf("%d\n",n);
}
//HAM KIEM TRA |X^N/N!<=C|
void check2(double c){
int n=1;
double t=1;
double x=2;
while(1){
t*=x/n;
if(fabs(t)<=c) break;
n++;
}
printf("%d\n",n);
}
//HAM KIEM TRA |X^(2*N+1)/(2*N+1)!<=C|
void check3(double c){
int n=3;
double x=2;
double t=x;
while(1){
if(fabs(t)<=c) break;
t*=x*x/(n*(n-1));
n+=2;
}
printf("%d\n",(n-1)/2);
}
int main(){
int n;
printf("Enter n = ");
scanf("%d", &n);
// for(int i=0; i<=n; i++){
// if(isPrime(i)==1) printf("%5d",i);
// }
// for(int i=0; i<=n; i++){
// if(isSquare(i)==1) printf("%5d",i);
// }
// for(int i=0; i<=n; i++){
// if(isPalindrome(i)==1) printf("%7d",i);
// }
if(isPerfect(n)==1) printf("True");
else printf("False");
// for(int i=0; i<=n; i++){
// if(isDivisible(i)==1) printf("%7d",i);
// }
// double c=0.00001;
// check1(c);
// check2(c);
// check3(c);
}