Out of boredom (and to put off studying) I decided to write a program to output Pascal's triangle, as well as calculate nCr. I started off using nats, but ran into a problem where the factorial function that I wrote would overflow the nat or int type once I tried to calculate anything greater than 13! or so. I then moved to using real, which now allows me to calculate up to 169!, which I'm sure is well outside the realm of practical use (which is good). The problem is when I try to output the triangle or individual nCr values, once I get to the row where n = 23, I start to generate numbers in scientific notation. My question is, in C++ you can use IOS flags to prevent the use of scientific notation and instead force decimal, can you do something similar in Turing? Also, is there already a factorial function that I just failed to find? I looked in the reference under math and didn't see anything, so I just wrote my own. Is this the kind of thing that I should submit in the submission forum when I'm done?
Any help will be apprecited.
I didn't find the right solution from the Internet.
When I first started progamming, in FORTRAN, some fifty odd years ago, we used problems like this as exercises.
We solved the problem by not calculating factorials at all.
Taking the 23rd row of Pascal's triangle as an example, the first few terms are 23C0, 23C1, 23C2, 23C4, ... which in terms of factorials are 23!/(0!*23!), 23!/(1!*22!), 23!/(2!*21!), 23!/(3!*20!), ... .
The first term is 1, and the second term, 23, is calculated by multiplying the first term by 23/1, for the next term multiply by 22/2 and then 21/3 and so on.
A loop generates them easily.
We used the same technique to generate trig, exponential and log tables from their Maclaurin series.