-
Notifications
You must be signed in to change notification settings - Fork 16
/
primes.c
54 lines (48 loc) · 878 Bytes
/
primes.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
int putchar(int c);
unsigned int __builtin_mod(unsigned int a, unsigned int b) {
while (a >= b) {
a -= b;
}
return a;
}
unsigned int __builtin_div(unsigned int a, unsigned int b) {
int ret = 0;
while (a >= b) {
a -= b;
ret += 1;
}
return ret;
}
void printstring (char* s) {
for (; *s; s++) {
putchar(*s);
}
}
void printint (int n) {
char buf_[10];
buf_[9] = '\0';
char* buf = buf_ + 9;
do {
buf--;
*buf = '0' + (n % 10);
n /= 10;
} while (n);
printstring(buf);
}
int isprime (int n) {
for (int i=2; i<n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
int main (void) {
for (int i=2; i<=100; i++) {
if (isprime(i)) {
printint(i);
putchar('\n');
}
}
return 0;
}