solve the pascal problems

2008-11-24 3:16 am
FOR LOOP

Question 1..

Write a program to calculate the product of first N positive integers.


The sample output is

Enter N: 5

1 x 2 x...x 5 = 120


Use variable Product to store the result.



Question 2..

The algorithm below calculates the sum of a set of integers.



1. Declare X and Sum to be integer variables.

2. Initialize variable Sum to zero.

3. Read in a number and store it into variable X.

4. As long as the value of X is not negative, repeat steps 5 to 6:

5. Assign the value of Sum + X to variable Sum.

6. Read in a number and store it into variable X.

7. Display the value of Sum.

回答 (1)

2008-11-24 5:23 am
✔ 最佳答案
就算你唔係我ge學生,我都唔想鼓勵你抄功課
寫D pseudo code比你參考下啦

1.

Declare Integer n, i, Product;

Product = 1;
Read n;
for i = 1 to n
{
Product = Product * i;
}
Write n;

...
話就話pseduo-code,但係同個真program都已經七八成似...
因為呢題要做ge野實在唔多...

第二題個algorithm都比埋你啦wo~照寫就得
自己寫啦~
Programming要多做先有進步
參考: Me


收錄日期: 2021-04-13 16:15:46
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20081123000051KK01913

檢視 Wayback Machine 備份