33 lines
620 B
C++
Raw Normal View History

2013-03-16 19:13:01 +02:00
// A simple program that builds a sqrt table
#include <math.h>
2016-07-09 11:21:54 +02:00
#include <stdio.h>
2016-07-09 11:21:54 +02:00
int main(int argc, char* argv[])
{
int i;
double result;
// make sure we have enough arguments
2016-07-09 11:21:54 +02:00
if (argc < 2) {
return 1;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
// open the output file
2016-07-09 11:21:54 +02:00
FILE* fout = fopen(argv[1], "w");
if (!fout) {
return 1;
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
2009-10-04 10:30:41 +03:00
// create a source file with a table of square roots
2016-07-09 11:21:54 +02:00
fprintf(fout, "double sqrtTable[] = {\n");
for (i = 0; i < 10; ++i) {
result = sqrt(static_cast<double>(i));
2016-07-09 11:21:54 +02:00
fprintf(fout, "%g,\n", result);
}
// close the table with a zero
2016-07-09 11:21:54 +02:00
fprintf(fout, "0};\n");
fclose(fout);
return 0;
}