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++

#include<iostream.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 (int i=p_height; i>=1; i--)
    {
        for (int j=p_space; j>=i; j--)
        {
            cout<<" ";
        }
        for (int k=1; k<=max_stars; k++)
        {
            cout<<"*";
        }
        max_stars-=2;
        cout<<endl;
    }

    return 0;
}


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

#include <iostream.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)
            {
                cout<<"*";
            }
            else
            {
                cout<<" ";
            }
        }
        px++;
        py--;

        cout<<endl;
    }

    return 0;
}

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

Java

  class PatternProg
  {
    public static void main(String args[])
    {
        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;

        for (int i=p_height; i>=1; i--)
        {
            for (int j=p_space; j>=i; j--)
            {
                System.out.print(" ");
            }
            for (int k=1; k<=max_stars; k++)
            {
                System.out.print("*");
            }
            max_stars-=2;
            System.out.println();
        }

    } //end of main
}  //end of class



/*-- Another Logic using if-else */
class PatternProg
{
    public static void main(String args[])
    {
        int n = 4; // size

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

        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j < n * 2; j++)
            {
                if (j >= px && j <= py)
                {
                    System.out.print("*");
                }
                else
                {
                    System.out.print(" ");
                }
            }
            px++;
            py--;

            System.out.println();
        }


    }
}

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

C#

using System;

class PatternProg
{
  public static void 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;

    for (int i = p_height; i >= 1; i--)
    {
      for (int j = p_space; j >= i; j--)
      {
        Console.Write(" ");
      }
      for (int k = 1; k <= max_stars; k++)
      {
        Console.Write("*");
      }
      max_stars -= 2;
      Console.WriteLine();
    }
    Console.ReadKey(true);
  } //end of main
} //end of class



/*-- Another Logic using if-else -

using System;

class PatternProg
 {
  public static void Main()
   {
    int n = 5; // size
    int px = 1; // print controls
    int py = n * 2 - 1;

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

     Console.WriteLine();
     }
     Console.ReadKey(true);
   }
 }
 /*--------------------------------*/

Python

decr = 7
for x in range(4, 0, -1):
    for y in range(x, 5):
        print(" ", end="")
    print("*" * decr)
    decr -= 2

Tutorial (YouTube)

5 2 votes
Rate this Program
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments