/* C program to print diamond star pattern */
*
***
*****
*******
*********
*******
*****
***
*
#include <stdio.h>
int main()
{
int i, j, n;
printf("Enter N : ");
scanf("%d", &n);
// Print the upper pyramid
for(i=1; i<=n; i++)
{
for(j=i; j<n; j++)
{
printf(" ");
}
for(j=1; j<=(2*i-1); j++)
{
printf("*");
}
printf("\n");
}
// Print the lower triangle
for(i=n; i>=1; i--)
{
for(j=i; j<=n; j++)
{
printf(" ");
}
for(j=2; j<(2*i-1); j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment