Add stdlib.h to mandelbrot.c and format it.
+#include <stdlib.h>
#include <stdio.h>
-int main (int argc, char **argv)
-{
+int main (int argc, char **argv) {
int w, h, bit_num = 0;
char byte_acc = 0;
int i, iter = 50;
@@ -12,15 +12,13 @@ int main (int argc, char **argv)
printf ("P4\n%d %d\n", w, h);
- for(y=0;y<h;++y)
- {
- for(x=0;x<w;++x)
- {
+ for (y = 0; y < h; ++y) {
+ for (x = 0; x < w; ++x) {
Zr = Zi = Tr = Ti = 0.0;
- Cr = (2.0*x/w - 1.5); Ci=(2.0*y/h - 1.0);
+ Cr = (2.0 * x / w - 1.5);
+ Ci = (2.0 * y / h - 1.0);
- for (i=0;i<iter && (Tr+Ti <= limit*limit);++i)
- {
+ for (i = 0; i < iter && (Tr + Ti <= limit * limit); ++i) {
Zi = 2.0 * Zr * Zi + Ci;
Zr = Tr - Ti + Cr;
Tr = Zr * Zr;
@@ -32,14 +30,11 @@ int main (int argc, char **argv)
++bit_num;
- if(bit_num == 8)
- {
+ if (bit_num == 8) {
putc (byte_acc, stdout);
byte_acc = 0;
bit_num = 0;
- }
- else if(x == w-1)
- {
+ } else if (x == w - 1) {
byte_acc <<= (8 - w % 8);
putc (byte_acc, stdout);
byte_acc = 0;
