# Thread: Nested loops - asterisk diamond

1. ## Nested loops - asterisk diamond

Getting close but I think I am stuck on the second loop. The input you put in will be doubled (and it's not supposed to). Any help much appreciated!!

Code:
```int main()
{
int n, i, j, k;

printf("What would you like the height to be? (Positive odd integer)\n");
scanf("%d", &n);

for(i=1; i <= n; i++)
{
for(j=1; j <= n-i; j++)
printf("%c", ' ');
for (k=1; k <= 2*i-1; k++)
printf("%c", '*');
printf("\n");
}

k = 1;
for(i=1; i <= n - 1; i++)
{
for(j=1; j <= k; j++)
printf(" ");
k++;
for (j=1; j <= 2*(n-i)-1; j++)
printf("*");
printf("\n");
}

return 0;
}```

2. Originally Posted by charl33t
Getting close but I think I am stuck on the second loop. The input you put in will be doubled (and it's not supposed to). Any help much appreciated!!
So divide n by 2, and use that value for the loops.

3. Thank you!! I got it figured out.

4. Code:
`for(i=1; i <= n; i++)`
well, it has no impact on your code, but more generally used in C form will be:
Code:
`for(i=0; i < n; i++)`
Since when you start working with arrays your variant will get you out of bound of array of n element.
So I would suggest to start using the second form already now to be regular with it when time comes.