Post Reply 
monic part 5: writing C programs on the calculator
01-01-2021, 11:20 AM (This post was last modified: 01-01-2021 11:23 AM by grsbanks.)
Post: #2
RE: monic part 5: writing C programs on the calculator
(01-01-2021 01:35 AM)F-73P Wrote:  the translator produces a sequence of codes. When the program is run the codes are fed to a switch statement, which executes the corresponding instruction. Does this make the translator a compiler, or is it an interpreter?

More like an interpreter. An interpreter executes the "translated" program as it is converting it (as does your system). A compiler transforms the original into something else that you can store and then run at a later date once the "translation" is complete.

A couple of optimisations of your code, BTW. You can't do "n--" if n is a floating point number. Also, this assumes that the value of n has been checked for validity and that it is in fact a positive integer value (expressed as a floating point).

Code:
int main(void) {
 double product = 1.0;
 unsigned int n = (unsigned int)level1;
 for(; n > 1;) product *= n--;
}

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: monic part 5: writing C programs on the calculator - grsbanks - 01-01-2021 11:20 AM



User(s) browsing this thread: 2 Guest(s)