有關programming code既功課問題

2009-02-05 10:12 pm
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *

這個鑽石形...怎樣用PROGRAMMING CODE(最好係C)寫出黎...

主要功能︰Print, for-loop
功課要二月十三日星期五前交....


可以俾code, 可以俾pascal code, 可以俾pseducode都得...因為我係唔識諗..並唔係想唔做功課,就咁copy落去

唔使全形ga..因為yahoo個系列幫我delete左放前面既space,所以用全形先整到個形狀show出黎

回答 (2)

2009-02-08 7:54 am
✔ 最佳答案
http://i377.photobucket.com/albums/oo217/ray1943/Diamond.png

#include <stdio.h>

const int MaxLevel= 5;

void PrintStar( int level)
{
int i, numberOfLeftPaddingSpaces= MaxLevel - level;

for( i=0; i<numberOfLeftPaddingSpaces; i++)
printf(" ");

for(i=0; i< 2*level-1; i++)
printf("*");

printf("\n");
}

void ProcessLevel( int level)
{
PrintStar( level);
if( level < MaxLevel)
{
ProcessLevel( level + 1);
PrintStar(level);
}
}

void main()
{
ProcessLevel( 1);
}
參考: Myself
2009-02-07 5:54 am
我淨係學過pascal, 用pascal code 答你, 雖然好似長左d, 不過我淨係諗到咁樣:

var
i,j:integer;
begin
for i:=1 to 5 do
begin
for j:=1 to 5-i do
write(' ');
for j:=1 to (1+2*(i-1)) do
write('*');
writeln;
end;
for i:=4 downto 1 do
begin
for j:=1 to 5-i do
write(' ');
for j:=1 to (1+2*(i-1)) do
write('*');
writeln;
end;
end.


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

檢視 Wayback Machine 備份