Simple programs to print star pattern in c
Posted by Nikhil Chawra 6/30/2012
Here there are some examples of Star pattern programs in c
Print the stars
You can also read this :-
Number Pattern Programs in C
How To Play Sounds In C Language
pattern1 : Print the stars
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,n;
clrscr();
printf("\nEneter the no of lines to be printed: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
Star pattern 2
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,n;
clrscr();
printf("\nEneter the no of lines to be printed: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=n-i;j>1;j--)
{
printf(" ");
}
for(j=0;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
Star pattern 3
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,n,k;
clrscr();
printf("\nEnter the no of lines to be printed: ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
printf("*");
}
for(k=0;k<(2*n-2*j);k++)
{
printf(" "); //for spaces
}
for(j=0;j<n-i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
Star pattern 4
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,n,k;
clrscr();
printf("\nEnter the no of lines to be printed: ");
scanf("%d",&n);
printf("\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
printf("*");
}
for(k=0;k<(2*n-2*j);k++)
{
printf(" ");
}
for(j=0;j<n-i;j++)
{
printf("*");
}
printf("\n");
}
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("*");
}
for(k=2*n-2*j;k>0;k--)
{
printf(" ");
}
for(j=0;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
Star pattern 5
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("\nEnter the no lines to be printed: ");
scanf("%d",&n);
printf("\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<(n-i-1);j++)
printf(" ");
for(k=0;k<(2*i+1);k++)
printf("*");
printf("\n");
}
for(i=0;i<n-1;i++)
{
for(j=0;j<=i;j++)
printf(" ");
for(k=(2*n-2*i-3);k>0;k--)
printf("*");
printf("\n");
}
}
Star pattern :6 [Diamond pattern]
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("Enter the number of lines to be printed");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=n-i-1;j>0;j--)
printf(" ");
printf("*");
for(k=2*i-1;k>0;k--)
printf(" "); //code for upper triangle
if(i!=0)
printf("*");
printf("\n");
}
for(i=n-1;i>0;i--)
{
for(j=0;j<n-i;j++)
printf(" ");
printf("*"); //code for lower triangle
for(k=2*i-3;k>0;k--)
printf(" ");
if(i!=1)
printf("*");
printf("\n");
}
getch();
}
pattern 7:program for simple star pyramid
simple star pyramid |
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,n;
//clrscr();
printf("Enter the number of lines to be ptinted");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
printf(" "); // spaces
}
for(k=0;k<2*i-1;k++)
{
printf("*"); // star
}
printf("\n");
}
}
pattern 8:program for simple star pyramid in reverse order
star pyramid reverse |
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,n;
//clrscr();
printf("Enter the number of lines to be ptinted");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
printf(" ");
}
for(k=2*(n-i)+1;k>1 ;k--)
{
printf("*");
}
printf("\n");
}
}
The program below is good program can be asked for coding compititions
pattern 9: program for arrow pattern
arrow pattern |
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("Enter the number of lines to be ptinted");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<i;j++)
{
printf(" ");
}
for(k=0;k<i;k++)
{
printf("*");
}
printf("\n");
} for(i=0;i<n;i++)
{
for(j=0;j<n-i;j++)
{
printf(" ");
}
for(k=0;k<n-i;k++)
{
printf("*");
}
printf("\n");
}
}
pattern 10: Not that Simple program to print hollow pattern triangle.
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("Enter the number of lines to be printed:");
scanf("%d",&n);
printf("\n");
for(i=1;i<2*(n-2);i++)
printf(" ");
printf("*\n");
for(i=1;i<n-1;i++)
{
for(j=n-i;j>0;j--)
printf(" ");
printf("*");
for(k=0;k<2*i-1;k++)
printf(" ");
printf("*\n");
}
printf(" ");
for(i=0;i<2*n-1;i++)
printf("*");
}
pattern 11: Simple Square pattern program in c
#include<conio.h>
#include<stdio.h>
void main()
{
int i,j,k,n;
clrscr();
printf("Enter the number of lines to be printed:");
scanf("%d",&n);
for(i=0;i<n;i++)
printf("*");
printf("\n");
for(i=0;i<n-2;i++)
{
printf("*");
for(j=0;j<n-2;j++)
printf(" ");
printf("*\n");
}
for(i=0;i<n;i++)
printf("*");
}
?
+
X
Recommended for you
Loading..
0 comments:
Post a Comment