Am trying to print hollow diamond pattern with * outline with minimum loops. I optimized with 2 loops. Is there any other way to still optimize this code
My output using 2 loops
void main()
{
int row,col,n,k;
printf("Enter no of rows: ");
scanf("%d",&n);
for(row=0, k=1; row<=2*n; row>n?k++:k, printf("\n"), row++)
for(col=-n; col<=n; col++)
(col>0?col:-col) < (row<=n?row:(row-2*k)) ? printf(" ") : printf("*");
}
Aucun commentaire:
Enregistrer un commentaire