Star patterns are a series of * or any other character used to create some pattern or any geometrical shape such as – square, triangle(Pyramid), rhombus, heart etc. These patterns are often prescribed by many c program books and are best for practicing flow control statement.
Program 1 :
#include<stdio.h>
#include<stdio.h>
int main()
{
int x;
for(x=0;x<=4;x++)
{
printf(“\n*”);
}
}
Output :
Program 2 :
#include<stdio.h>
#include<stdio.h>
int main()
{
int x;
for(x=0;x<=4;x++)
{
printf(“*”);
}
}
Output :
Program 3 :
#include<stdio.h>
#include<stdio.h>
int main()
{
int x,y;
for(x=0;x<=4;x++)
{
for(y=0;y<=4;y++)
{
printf(“*”);
}
printf(“\n”);
}
}
Output :
Program 4 :
#include<stdio.h>
#include<stdio.h>
int main()
{
int x,y,N;
printf(“Enter the number of row = “);
scanf(“%d”,&N);
for(x=1;x<=N;x++)
{
for(y=1;y<=x;y++)
{
printf(“*”);
}
printf(“\n”);
}
}
Output :
Program 5 :
#include<stdio.h>
#include<stdio.h>
int main()
{
int x,y;
for(x=0;x<=4;x++)
{
for(y=4;y>=x;y–)
{
printf(“*”);
}
printf(“\n”);
}
}
Output :
Program 6 :
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z,N;
printf(“Enter the number of row = “);
scanf(“%d”,&N);
for(x=1;x<=N;x++)
{
for(y=N-1;y>=x;y–)
{
printf(” “);
}
for(z=1;z<=x;z++)
{
printf(“*”);
}
printf(“\n”);
}
}
Output :
Program 7 :
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
for(x=5;x>=1;x–)
{
for(y=4;y>=x;y–)
{
printf(” “);
}
for(z=1;z<=x;z++)
{
printf(“*”);
}
printf(“\n”);
}
}
Output :
Program 8 :
#include<stdio.h>
#include<conio.h>
main()
{
int x,y;
for(x=1;x<=5;x++)
{
for(y=1;y<=9;y++)
{
if(y<=x||y>9-x)
{
printf(“*”);
}
else
{
printf(” “);
}
}
printf(“\n”);
}
}
Output :
Program 9 :
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z,N;
printf(“Enter the number of row = “);
scanf(“%d”,&N);
for(x=1;x<=N;x++)
{
for(y=N-1;y>=x;y–)
{
printf(” “);
}
for(z=1;z<=x;z++)
{
printf(“* “);
}
printf(“\n”);
}
}
Output :
Program 10 :
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
for(x=5;x>=1;x–)
{
for(y=4;y>=x;y–)
{
printf(” “);
}
for(z=1;z<=x;z++)
{
printf(“* “);
}
printf(“\n”);
}
}
Output :
Program 11 :
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y;
for(x=3;x>=-3;x–)
{
for(y=3;y>=abs(x);y–)
{
printf(” * “);
}
printf(“\n”);
}
}
Output :
Program 12 :
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y,z;
for(x=3;x>=-3;x–)
{
for(y=1;y<=abs(x);y++)
{
printf(” “);
}
for(z=3;z>=abs(x);z–)
{
printf(“*”);
}
printf(“\n”);
}
}
Output :
Program 13 :
#include<stdio.h>
#include<conio.h>
int main()
{
int x,y;
for(x=1;x<=5;x++)
{
for(y=1;y<=5;y++)
{
if(y==3||x==3)
{
printf(“*”);
}
else
{
printf(” “);
}
}
printf(“\n”);
}
}