Code Box
-------------------------------------
/* Program to print diamond pattern 8 */
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, k,n;
clrscr();
printf("Enter the number of stars: ");
scanf("%d",&n);
printf("\n---------------Diamond pattern-------------------\n");
for (i = 1; i <= n; i++)
{
for (j = 0; j < (n - i); j++)
printf(" ");
for (j = 1; j <= i; j++)
printf("%d",j);
for (k = j; k>=1; k--)
printf(" ");
printf("\n");
}
for (i = n - 1; i >= 0; i--)
{
for (j = 0; j < (n - i); j++)
printf(" ");
for (j = 1; j <= i; j++)
printf(" ");
for (k = j; k>=1; k--)
printf("%d",k);
printf("\n");
}
printf("\n");
printf("\n----------------------------------\n");
getch();
}
No comments:
Post a Comment