Asked in
Computer Programming
Java Programming
C Programming

Can you write any simple c program without header file?

Answer

User Avatar
Wiki User
July 19, 2009 6:40PM

Yes you (usually) can, though it may depend on your particular C implementation.

// A complete (if useless) C program to compute the square root of 2 and then exit.

// No headers required.

double sqroot(const double s) {

double xn = s / 2.0;

double lastX = 0.0;

while(xn != lastX) {

lastX = xn;

xn = (xn + s/xn) / 2.0;

}

return xn;

}

int main() {

double sqrt2 = sqrt(2);

return 0;

}