Square And Rhombus Star Pattern
In this topic, we will learn how to create the patterns by using C language. We will create the patterns by using either a '*' star character or some other character. We will create different patterns or a geometrical shape such as triangle, square, rhombus etc.
Square Star Pattern Program
C Program
//Square Star Pattern
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows: ");
scanf("%d",&n);
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}
Output:
Hollow Square Star Pattern Program
C Program
//Hollow Square Star Pattern
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows: ");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==1 ||i==n||j==1||j==n)
{
printf("*");
}
else
printf(" ");
}
printf("\n");
}
return 0;
}
Output:
Hollow Square Star Pattern With Diagonal Program
C Program
//Hollow Square Pattern with Diagonal
#include <stdio.h>
int main()
{
int n;
printf("Enter the number of rows: ");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i==1 ||i==n||j==1||j==n-i+1||i==j||j==n)
{
printf("*");
}
else
{
printf(" ");
}
}
printf("\n");
}
return 0;
}
Output: