Print a Diamond in C using for loop
int n, nol,spaces,stars; //nol=number of lines
printf("Enter the radius of the Diamond\n");
scanf("%d" , &n);
for(nol=1; nol<=n; nol++)
{
for(spaces=n-1; spaces>=nol; spaces--)
{
printf(" ");
}
for(stars=1; stars<=nol; stars++)
{
printf("*");
printf(" ");
}
printf("\n");
}
for(nol=1; nol<=n; nol++)
{
for(spaces=1; spaces<=nol; spaces++)
{
printf(" ");
}
for(stars=n-1; stars>=nol; stars--)
{
printf("*");
printf(" ");
}
printf("\n");
}
return 0;
}
diamond in c using foor loop |