File: factorial.tiny

package info (click to toggle)
pyparsing 3.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 12,200 kB
  • sloc: python: 30,867; ansic: 422; sh: 112; makefile: 24
file content (23 lines) | stat: -rw-r--r-- 493 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* Sample program in Tiny language – computes factorial
   from https://a7medayman6.github.io/Tiny-Compiler/
*/
int main()
{
    int x;
    read x; /*input an integer*/

    if x > 0 /*don’t compute if x <= 0 */
    then
        int fact := 1;
        repeat
            fact := fact * x;
            x := x - 1;
        until x = 0
        write fact; /*output factorial of x*/
    elseif x = 0 then
        write 1;
    else
        write "Error: x must be >= 0";
    end
    return 0;
}