您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

在C语言中编写一个程序来打印实心和空心菱形图案

2025/12/17 14:12:53发布19次查看
程序说明打印如下所示的实心和空心菱形图案
算法对于空心菱形 -
accept the number of rows for hollow rhombus from the usercreate a hollow rhombus containing the same number of rows specified by the user.print the first row containing the number of stars same as the number of rows.print the second row containing the first and last star as show in the output and leave the spaces between first and the last star.do the same till you reach the last row.print the last row containing the number of stars same as the number of rows.
for solid rhombus −
accept the number of rows for solid rhombus from the usercreate a solid rhombus containing the same number of rows specified by the user.print the first row containing the number of stars same as the number of rows.do the same till you reach the last row.
example的中文翻译为:示例/* program to print hollow and solid rhombus star pattern */#include <stdio.h>int main() { int r, c, rows; //hollow rhombus int r1,c1, rows1; //solid rhombus clrscr(); printf("enter the number of rows for hollow rhombus pattern: "); scanf("%d", &rows); printf("
"); for(r=1; r<=rows; r++){ for(c=1; c<=rows-r; c++){ printf(" "); } for(c=1; c<=rows; c++){ if(r==1 || r==rows || c==1 || c==rows) printf("*"); else printf(" "); } printf("
"); } printf("
"); printf("enter the number of rows for solid rhombus pattern: "); scanf("%d", &rows1); printf("
"); for (r1=1; r1<=rows1; r1++){ for (c1=1; c1<=rows1-r1;c1++){ printf(" "); } for (c1=1; c1<=rows1; c1++){ printf("*"); } printf("
"); } getch(); return 0;}
输出
以上就是在c语言中编写一个程序来打印实心和空心菱形图案的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product