用 C 语言打印菱形图案的程序
程序说明
菱形图案是简单金字塔图案和倒置金字塔图案的结合。
算法
First Row: Display 1 Second Row: Display 1,2,3 Third Row: Display 1,2,3,4,5 Fourth Row: Display 1,2,3,4,5,6,7 Fifth Row: Display 1,2,3,4,5,6,7,8,9 Display the same contents from 4th Row till First Row below the fifth Row.
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.
示例
/* Program to print Diamond Pattern */ #include<stdio.h> int main(){ int i,j,k; clrscr(); printf("
"); printf("Diamond Pattern"); printf("
"); printf("
"); for(i = 1;i<=5;i++){ for(j = i;j<5;j++){ printf(" "); } for(k = 1;k<(i*2);k++){ printf("%d",k); } printf("
"); } for(i = 4;i>=1;i--){ for(j = 5;j>i;j--){ printf(" "); } for(k = 1;k<(i*2);k++){ printf("%d",k); } printf("
"); } getch(); return 0; }
输出
广告