tpw (n!=1+2+3+.......+n的code)

2010-03-14 12:25 am
N!=1+2+3+4+5+...N
有無人識打e個code=-=
help

回答 (1)

2010-03-14 3:01 am
✔ 最佳答案
N factorial is defined as :
N! = 1 X 2 X 3 X . . . X N


The following is a simple program written in tpw using "repeat . . . until" for your reference :

uses wincrt;

var
 n, i, fact : real;

begin
 write('Input a positive integer: ');
 readln(n);
 i:=0;
 fact:=1;
 repeat
  i:=i+1;
  fact:=fact*i;
 until i=n;
 writeln(n:1:0, '! = ', fact:1:0);
end.


If you really want to find the value of 1 + 2 + 3 + . . . + N,
then change fact:=1; to fact:=0;
and change fact:=fact*i; to fact:=fact+i;


收錄日期: 2021-04-13 17:08:34
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20100313000051KK01028

檢視 Wayback Machine 備份