
在这里,为了以菱形图案打印星星,我们使用嵌套的 for 循环。
我们用于以菱形图案打印星星的逻辑如下所示 -
//For upper half of the diamond the logic is: for (j = 1; j "); }
假设让我们考虑 rows=5,它打印输出如下 -
* *** ***** ******* *********
//For lower half of the diamond the logic is: for (j = 1; j "); }
假设 row=5,将打印以下输出 -
******* ***** *** *
示例
#include <stdio.h>
int main(){
int rows, i, j;
printf("Enter no of rows<p>");
scanf("%d", &rows);
for (j = 1; j </p>
<p>");
}
for (j = 1; j </p>
<p>");
}
return 0;
}</p></stdio.h>
输出
Enter no of rows 5 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
13万字C语言保姆级教程(深入):立即使用
在学习笔记中,你将探索c语言的核心概念和高级技巧!











