阶乘.txt

来自「PL0语言的编译器」· 文本 代码 · 共 28 行

TXT
28
字号
\\程序完成的是 n! 的连加和,从 1 到 所输入的值
\\输入的值应该小于13,因为超过这个界限会导致数的越界

var   subresult , result , upperbound , i , flag;       
begin  
     read(flag);
     while  flag=0  do                                    \\是否进行运算
     begin
          read(upperbound);                            \\读入数据
          write(upperbound);                           \\反写出读入的数据
          i := 0;                                                
          result:=0;
          if   upperbound>=0 then                   \\判断读入的数据是否正确
                if    upperbound<=12 then         \\两个if 实现 && 的功能
                      while   i<=upperbound  do
                                begin
                                        if   i = 0  then
                                             subresult := 1;                                    

                                        if   i # 0  then
                                              subresult := subresult * i;
                                        result := result + subresult ;
                                        i := i+1
                                end;
          write(result);
          read(flag)                                         \\是否继续
     end;
end. 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?