程式碼:
#include <stdio.h>
int main()
{
int n, c, k, space = 1;
printf("您要幾行鑽石星星?\n");
scanf("%d", &n);
space = n - 1;
for (k = 1; k <= n; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space--;
for (c = 1; c <= 2*k-1; c++)
printf("*");
printf("\n");
}
space = 1;
for (k = 1; k <= n - 1; k++)
{
for (c = 1; c <= space; c++)
printf(" ");
space++;
for (c = 1 ; c <= 2*(n-k)-1; c++)
printf("*");
printf("\n");
}
return 0;
}
執行結果:
您要幾行鑽石星星?
5
*
***
*****
*******
*********
*******
*****
***
*
--------------------------------
Process exited after 3.797 seconds with return value 0
請按任意鍵繼續 . . .
p.s.
執行C語言工具
Windows系統 : 下載Dev C++
Android系統 : 下載CppDroid
沒有留言:
張貼留言