Monday, 1 February 2016

Print Star Pattern in C

Print Star Pattern in C

Hello friends Today we write code for Print Star Pattern in C or Print Triangle of star in C . For this program you need for loop concept and break line concept.

Code for Star Triangle

#include <stdio.h>
#include <conio.h>
 void main()
{
 int row, c, n, temp;
 printf("Enter the number of rows in pyramid of stars you want to see: ");
 scanf("%d",&n); temp = n;
 for ( row = 1 ; row <= n ; row++ )
 {
 for
 ( c = 1 ; c < temp ; c++ )
 printf(" "); temp--;
 for ( c = 1 ; c <= 2*row - 1 ; c++ )
 printf("*");
 printf("\n");
 }
 getch();
}

Output:

Enter the number of rows in pyramid of stars you want to see: 5
        *
      ***
    *****
  *******
*********

Print Below Pattern

*
**
***
****
*****

Code for Above Pattern


#include <stdio.h>
#include <conio.h>
void main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

No comments:

Post a Comment