MakeTable.cxx 638 B

1234567891011121314151617181920212223242526272829303132333435
  1. // A simple program that builds a sqrt table
  2. #include <stdio.h>
  3. #include <math.h>
  4. int main (int argc, char *argv[])
  5. {
  6. int i;
  7. double result;
  8. // make sure we have enough arguments
  9. if (argc < 2)
  10. {
  11. return 1;
  12. }
  13. // open the output file
  14. FILE *fout = fopen(argv[1],"w");
  15. if (!fout)
  16. {
  17. return 1;
  18. }
  19. // crate a source file with a table of square roots
  20. fprintf(fout,"double sqrtTable[] = {\n");
  21. for (i = 0; i < 10; ++i)
  22. {
  23. result = sqrt(static_cast<double>(i));
  24. fprintf(fout,"%g,\n",result);
  25. }
  26. // close the table with a zero
  27. fprintf(fout,"0};\n");
  28. fclose(fout);
  29. return 0;
  30. }