瀏覽單個文章
chou121
*停權中*
 

加入日期: May 2001
您的住址: Taipei
文章: 22
純 C 的程式

#include <stdio.h>

#ifdef __cplusplus
extern "C" {
#endif

#define ROWCnt 9

void Case1()
{
int rowIdx;
int idx, starCnt;

printf("Case 1:\n");
for (rowIdx = 0; rowIdx < ROWCnt; rowIdx++)
{
starCnt = ((rowIdx < ROWCnt / 2) ? rowIdx + 1 : ROWCnt - rowIdx);
for (idx = 0; idx < starCnt; idx++)
printf("*");
printf("\n");
}
printf("\n");
}

void Case2()
{
int rowIdx;
int idx, spaceCnt, starCnt;

printf("Case 2:\n");
for (rowIdx = 0; rowIdx < ROWCnt; rowIdx++)
{
spaceCnt = ((rowIdx < ROWCnt / 2) ? rowIdx : ROWCnt - rowIdx - 1);
starCnt = ROWCnt - 2 * spaceCnt;
for (idx = 0; idx < spaceCnt; idx++)
printf(" ");
for (idx = 0; idx < starCnt; idx++)
printf("*");
printf("\n");
}
printf("\n");
}

int main()
{
Case1();
Case2();
return 0;
}

#ifdef __cplusplus
}
#endif
舊 2005-04-01, 09:10 AM #57
回應時引用此文章
chou121離線中