This code print diamond pattern of stars. Diamond shape is as follows:
1 |
* |
1 |
*** |
1 |
***** |
1 |
*** |
1 |
*<!--more--> |
1 |
1 |
#include <stdio.h> |
1 |
#include <conio.h> |
1 |
int main() |
1 |
{ |
1 2 |
int n, c, k, space = 1; printf("Enter number of rows<b>\n</b>"); |
1 |
scanf("%d", &n); |
1 |
space = n - 1; |
1 |
for (k = 1; k <= n; k++) |
1 |
{ |
1 |
for (c = 1; c <= space; c++) |
1 |
printf(" "); |
1 |
space--; |
1 |
for (c = 1; c <= 2*k-1; c++) |
1 |
printf("*"); |
1 |
printf("<b>\n</b>"); |
1 |
} |
1 |
space = 1; |
1 |
for (k = 1; k <= n - 1; k++) |
1 |
{ |
1 |
for (c = 1; c <= space; c++) |
1 |
printf(" "); |
1 |
space++; |
1 |
for (c = 1 ; c <= 2*(n-k)-1; c++) |
1 |
printf("*"); |
1 |
printf("<b>\n</b>"); |
1 |
} |
1 |
return 0; |
1 |
} |