patternprogram_163 softethics

Pattern 163 (Reverse Pyramid II)

C

#include<stdio.h>

int main()
{
  int p_height=4; //change value to increase or decrease the size of piramid

  int max_stars=p_height*2-1;

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


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

/*-- Another Logic using if-else */

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

  int px = 1; // print controls
  int py = n*2-1;

  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 2 votes
Rate this Program
Subscribe
Notify of
guest


0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments