help!!!pascal

2007-03-19 3:03 am
pascal


唔識點做請各位教下我
如果要寫一個程式你輸入佢既邊長就會顯示個正方形出黎例如你輸入5
佢就顯示
*****
* *
* *
* *
*****

回答 (4)

2007-03-19 4:52 pm
✔ 最佳答案
閣下可以試一下以下的algorithm:
1. Define variable side as integer
2. Define variables i, j as integer
3. Display "Please input the length of one side of the square: "
4. Read user input and store as side
5. if side is greater than zero
5.1 if side is greater than 1
5.1.1 if side is greater than or equal 2 (* display top side *)
5.1.1.1 for i equals 1 to side
5.1.1.1.1 display "*"
5.1.1.2 Display line feed
5.1.2 if side is greater than 2 (* display left right sides *)
5.1.2.1 for i equals 2 to side - 1
5.1.2.1.1 Display "*"
5.1.2.1.2 for j equals 1 to side - 1
5.1.2.1.2.1 Display blank character
5.1.2.1.3 Display line feed
5.1.1 if side is greater than or equal 2 (* display bottom side *)
5.1.1.1 for i equals 1 to side
5.1.1.1.1 display "*"
5.1.1.2 Display line feed

5.2 else
5.2.1 Display "*" and line feed
6 else
6.1 Display "Please input length of positive value!"
2007-03-22 1:04 am
var i,j,n:integer;
begin
readln(n); {輸入行數}
for i:=1 to n do write('*'); {第一橫行}
writeln;
for i:=1 to n-2 do {中間有n-2行, 每行只有兩粒}
begin
write('*'); {先印第一粒}
for j:=1 to n-2 do write(' '); {再印n-2個空格}
writeln('*'); {印最後一粒及換行}
end;
for i:=1 to n do write('*'); {印最後一行}
writeln;
end.

2007-03-21 22:39:39 補充:
做得呢個問題, 估計都係初學, 所以應該好多野未學到, 例如字串函數, 陣列(數組)等, 呢修題應該想考學生運用循環, 包括一層和兩層循環的技巧。所以程式中沒有使用後面才學到的東西。另外加上注解, 方便學習, 但yahoo把我的單引號全部變成 '
2007-03-21 9:36 pm
program rect;
uses wincrt;
const
star = '************************************************************';
space = ' ';
var
line : array[1..100] of string;
long , w : integer;
i: integer;

begin

writeln('Enter :');
readln(long);

line[1] := copy(star,1,long);
line[long] := copy(star,1,long);
for i:= 2 to long-1 do
line[i] := '*'+copy(space,1,long-2)+'*';
for w:= 1 to long do
writeln(line[w]);
end.
2007-03-19 7:37 pm
please check following code:

program PrnSign00;

var
iShow : integer;
iLoop : integer;

procedure ShowSign0( iShow : integer );
var
i : integer;
begin
for i := 1 to iShow do
write( '*' );
writeln( );
end;

procedure ShowSign1( iShow : integer );
var
i : integer;
begin
for i := 1 to iShow do
begin
if ( i = 1 ) or ( i = iShow ) then
write( '*' )
else
write( ' ' );
end;
writeln( );
end;

begin
write( 'Enter show number : ' );
readln( iShow );
iLoop := 0;
if iShow <= 0 then
write( 'CANNOT SHOW!!!' )
else if iShow = 1 then
write( '*' )
else
begin
for iLoop := 1 to iShow do
begin
if ( iLoop = 1 ) or ( iLoop = iShow ) then
ShowSign0( iShow )
else
ShowSign1( iShow );
end;
end;
end.


here is the testing output:
U:\Pascal>PrnSign00
Enter show number : 9
*********
* *
* *
* *
* *
* *
* *
* *
*********

U:\Pascal>PrnSign00
Enter show number : 5
*****
* *
* *
* *
*****

U:\Pascal>



hope can help u


收錄日期: 2021-04-12 21:12:08
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070318000051KK04277

檢視 Wayback Machine 備份