@* A Simple CWEB Document. This is a simple CWEB document that incorporates documentation and code for a short C program that prints square roots of real numbers. Running `./sqrt 25.0' at the shell will print 5. @c @
@/ @@/ @ The standard headers are included to start with, @
= #include #include @* The Program. Here is the program to find the square root of a number. @= int main(int argc, char* argv[]) { if (argc < 2) { printf("Usage: sqrt \n"); exit(1); } printf("%15s %15s\n", "NUMBER", "SQUARE ROOT"); for (; argc > 1; --argc) { double n = atof(argv[argc - 1]); printf("%15.4f %15.4f\n", n, sqrt(n)); } return 0; } @ Now that we have used the |sqrt()| function, we need to include the appropriate header file. @
= #include