Pascal programming

2007-02-25 10:54 pm
我想問下點用pragram係4個數字中搵到最大值(largest)同最小值(smallest)
例如:100 ,5.2, 8.5, 2 中
Largest = 100 Smallest=2
更新1:

(Var 最好用integer 同 real ,唔好用其他)

回答 (2)

2007-02-26 5:26 pm
✔ 最佳答案
i hd posted a program in http://hk.knowledge.yahoo.com/question/?qid=7007022206008. Pls chk it. Also post the code in here.

program MaxMin_key;
uses crt;
var
d, l, n, s : double;
begin
l := 0;
s := 0;
writeln('Enter numbers (0 to stop)');
repeat
readln(n);
if l = 0 then
l := n;
if s = 0 then
s := n;

if n <> 0 then
begin
if l < n then
l := n;
if s > n then
s := n;
end;
until n=0;
writeln('Largest=',l);
writeln('Smallest=',s);
d := l - s;
writeln('Difference=',d)
end.

hope can help u
2007-02-25 11:48 pm
program large_and_small;
var
a,b,c,d:real;
large,small:real;
begin
write(&#39;Please input four numbers: &#39;);
read(a,b,c,d);
if (a&gt;b) and (b&gt;c) and (c&gt;d) then
large:=a;
if (b&gt;c) and (c&gt;d) and (d&gt;a) then
large:=b;
if (c&gt;d) and (d&gt;a) and (a&gt;b) then
large:=c;
if (d&gt;a) and (a&gt;b) and (b&gt;c) then
large:=d;
if (a

2007-02-25 15:49:35 補充:
未試過test...唔知run唔run到...

2007-02-27 19:48:31 補充:
上面果個..好似唔得,用呢個@@

2007-02-27 19:51:07 補充:
Program a;var a,b,c,d:integer;

2007-02-27 19:51:39 補充:
begin writeln(&#39;Input four numbers&#39;); readln(a,b,c,d);

2007-02-27 19:51:58 補充:
if (a&gt;b)and(b&gt;c)and(c&gt;d) then writeln(&#39;Largest = &#39;,a,&#39; Smallest = &#39;,d); if (b&gt;c)and(c&gt;d)and(d&gt;a) then writeln(&#39;Largest = &#39;,b,&#39; Smallest = &#39;,a);

2007-02-27 19:52:17 補充:
if (c d)and(d a)and(a b) then writeln(&#39;Largest = &#39;,c,&#39; Smallest = &#39;,b); if (d a)and(a b)and(b c) then writeln(&#39;Largest = &#39;,d,&#39; Smallest = &#39;,c);end.
參考: 自己


收錄日期: 2021-04-26 16:09:36
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070225000051KK02835

檢視 Wayback Machine 備份