๐ diamond structure in c programming
#include <stdio.h>
//@codewithsandhan
void main()
{
int i, j, a;
printf("Enter a number: ");
scanf("%d", &a);
for (i = a; i >= -a; i--)
{
for (j = -a; j <= a; j++)
{
if ((j <= 3.4 * a / 5 && j >= -3.4 * a / 5 && i == 4 * a / 5) || (i == j + a + 12 * a / 25 && i < 4 * a / 5 && i >= a / 5) || (i == -j + a + 12 * a / 25 && i < 4 * a / 5 && i >= a / 5) || (i == -j - 14 * a / 25 && i < 2.5 * a / 5 && i > -2.8 * a / 5) || (i == j - 14 * a / 25 && i >= -2.8 * a / 5))
{
printf("*");
}
else
{
printf(" ");
}
if (j == a)
{
printf("\n");
}
}
}
Comments
Post a Comment