Hi everyone. I need help getting my program to print a hexagon made of asterisks. I can get the program to print a solid hexagon, but I need a hollow hexagon. Can anyone help me out?
Code:
#include<stdio.h>
int main(void)
{
int length, i=0, j=0, k, l;
printf("Please enter the length for the sides of the hexagon:");
scanf("%d", &length);
for(i = 1, k=length, l=2*length-1; i<length; i++, k--, l++)
{
for(j = 0; j < 3*length; j++)
{
if(j>=k && j<=l)
{
printf("*");
}
else
printf(" ");
}
printf("\n");
}
for(i = 0, k=1, l=3*length-2; i<length; i++, k++, l--)
{
for(j=0; j<3*length;j++)
{
if(j>=k && j<=l)
printf("*");
else
printf(" ");
}
printf("\n");
}
}
It looks like this:
but it needs to look like this: