-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathfizzbuzz.c
55 lines (50 loc) · 964 Bytes
/
fizzbuzz.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
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 main (void) {
int printed;
for (int i=1; i<=30; i++) {
printed = 0;
if (i % 3 == 0) {
printstring("Fizz");
printed = 1;
}
if (i % 5 == 0) {
printstring("Buzz");
printed = 1;
}
if (!printed) {
printint(i);
}
putchar('\n');
}
return 0;
}