C Program to print diamond star pattern
Write a C program to print diamond star pattern series using for loop. How to print diamond star pattern structure in C program. Logic to print diamond star pattern series in C programming.
#include <stdio.h>
int main()
{
int i, j, rows;
int stars, spaces;
printf("Enter rows to print : ");
scanf("%d", &rows);
stars = 1;
spaces = rows - 1;
for(i=1; i<rows*2; i++)
{
for(j=1; j<=spaces; j++)
printf(" ");
for(j=1; j<stars*2; j++)
printf("*");
printf("\n");
if(i<rows)
{
spaces--;
stars++;
}
else
{
spaces++;
stars--;
}
}
return 0;
}
OUTPUT:
No comments:
Post a Comment