#include <stdio.h> #include <math.h> int main() { int n; if (scanf("%d", &n) != 1 || n <= 0 || n % 2 == 0) { printf("input error"); return 0; } int mid = (n + 1) / 2; // 菱形的中心行号 for (int i = 1; i <= n; i++) { int spaces = fabs(mid - i); // 打印空格的数量 int stars = n - 2 * spaces; // 打印星号的数量 for (int j = 0; j < spaces; j++) { printf(" "); } for (int j = 0; j < stars; j++) { printf("* "); } printf("\n"); } return 0; }
c语言编程练习题:7-59 打印菱形图案
作者:yunjinqi
类别:编程
日期:2023-05-29 17:30:57
阅读:571 次
消耗积分:0 分
版权所有,转载本站文章请注明出处:云子量化, https://www.yunjinqi.top/article/184
最新文章
系统当前共有 404 篇文章