/*程序运行结果:
1234567
1 #
2 ###
3 #####
4 #######
5 #####
6 ###
7 #
*/
#include <stdio.h>
#include <stdlib.h>
void diamond(int, int, char);
int main(void)
{
diamond(7, 7, ‘#‘); //打印7行7列#字排列的菱形图案
return0;
}
void diamond(int line, int col, char ch)
{
int i, j, key, space, count;
key = col / 2 + 1; //存储菱形列数的中心值
for(i = 1; i <= col; i++)
{
space = abs(key - i); //存储每行空格数量
for(j = 1; j <= space; j++)
printf(" ");
count = col - space * 2; //存储每行#字数量
while(count)
{
printf("%c", ch);
--count;
}
printf("\n");
}
return;
}
时间: 2024-11-17 20:04:20