patternprogram_139 softethics

Pattern 139 (Pyramid II)

C

#include<stdio.h>

int main()
{
  int min_stars=1;
  /*
    change value of min_stars to set min. no. of stars in
    piramid
    take odd no. for odd no. of stars in each row 1-3-5 etc
    take even no. for even no. stars in each row, 2-4-6 etc
  */
  int p_height=5; //change value to increase or decrease the size of piramid

  int p_space=p_height-1;
  int i,j,k;


  for(i=0; i<p_height; i++)
  {
    for(j=p_space; j>i; j--)
    {
      printf(" ");
    }
    for(k=0; k<min_stars; k++)
    {
      printf("*");
    }
    min_stars+=2;
    printf("\n");
  }
}


/*------- Another Logic -------*/

#include <stdio.h>
int main()
{
  int n = 5; // size

  int px = n; // left print control
  int py = n; // right print control

  int i,j; // loop var

  for(i = 1; i <= n; i++)
  {
    for(j = 1; j < n*2; j++)
    {
      if (j>=px && j<=py)
      {
        printf("*");
      }
      else
      {
        printf(" ");
      }
    }
    px--;
    py++;

    printf("\n");
  }

  return 0;
}

/*--------------------------------*/

C++

Java

C#

Python

Tutorial (YouTube)

5 1 vote
Rate this Program
Subscribe
Notify of
guest


0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments