*停權中*
|
純 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
|