Pyramid Programs

Half Star Pyramid
/*
  C program 
  Half Star Pyramid
*/

#include <stdio.h>
//Display Pyramid 
void print_pyramid(int size)
{

  int i=0,j=0;

  for(i=0; i < size ;i++){
    
    //Include space in front of star symbol
    for(j=1;j<(size)-i;j++)
    {
      printf(" ");
    }
    
    //Display star
    for(j=0;j<=i;j++)
    {
      printf("*");
    }
    
    printf("\n");
  }
}

int main()
{
  //Test Case
  print_pyramid(5);
  print_pyramid(7);
  return 0;
}


Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
#include<iostream>

using namespace std;

/*
  C++ Program
  Left Half Star Pyramid
*/
class MyPattern {
  public:

    //Display Pyramid 
    void print_pyramid(int size) {
      int i = 0, j = 0;
      for (i = 0; i < size; i++) {
        //Include space in front of star symbol

        for (j = 1; j < (size) - i; j++) {
          cout << " ";
        }
        //Display star

        for (j = 0; j <= i; j++) {
          cout << "*";
        }
        cout << "\n";
      }
    }
};
int main() {
  MyPattern obj = MyPattern();
  //Test Case
  obj.print_pyramid(5);
  obj.print_pyramid(7);
  return 0;
}

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
/*
  Java Program
  Left Half Star Pyramid
*/

public class MyPattern {
 
  //Display Pyramid 
  public void print_pyramid(int size)
  {

    int i=0,j=0;

    for(i=0; i < size ;i++){
      
      //Include space in front of star symbol
      for(j=1;j<(size)-i;j++)
      {
        System.out.print(" ");
      }
      
      //Display star
      for(j=0;j<=i;j++)
      {
        System.out.print("*");
      }
      
      System.out.print("\n");
    }
  }
  public static void main(String[] args) {

    MyPattern obj = new MyPattern();
    //Test Case
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
/*
  C# Program
  Left Half Star Pyramid
*/
using System;


public class MyPattern {
  //Display Pyramid 
  public void print_pyramid(int size) {
    int i = 0, j = 0;
    for (i = 0; i < size; i++) {
      //Include space in front of star symbol

      for (j = 1; j < (size) - i; j++) {
        Console.Write(" ");
      }
      //Display star

      for (j = 0; j <= i; j++) {
        Console.Write("*");
      }
      Console.Write("\n");
    }
  }
  public static void Main(String[] args) {
    MyPattern obj = new MyPattern();
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
<?php
/*
  Php Program
  Left Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 

  public  function print_pyramid($size) {
    $i = 0;
    $j = 0;
    for ($i = 0; $i < $size; $i++) {
      //Include space in front of star symbol

      for ($j = 1; $j < ($size) - $i; $j++) {
        echo(" ");
      }
      //Display star

      for ($j = 0; $j <= $i; $j++) {
        echo("*");
      }
      echo("\n");
    }
  }
}

function main() {
  $obj = new MyPattern();
  //Test Case

  $obj->print_pyramid(5);
  $obj->print_pyramid(7);

}
main();

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
/*
  Node Js Program
  Left Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  print_pyramid(size) {
    var i = 0;
    var j = 0;
    for (i = 0; i < size; i++) {
      //Include space in front of star symbol

      for (j = 1; j < (size) - i; j++) {
        process.stdout.write(" ");
      }

      //Display star

      for (j = 0; j <= i; j++) {
        process.stdout.write("*");
      }

      process.stdout.write("\n");
    }
  }
}

function main(args) {
  var obj = new MyPattern();
  //Test Case
  obj.print_pyramid(5);
  obj.print_pyramid(7);
}

main();

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
# Python 3 Program
# Left Half Star Pyramid
class MyPattern :
   # Display Pyramid 
  def print_pyramid(self, size) :
    i = 0
    j = 0
    i = 0
    while (i < size) :
       # Include space in front of star symbol
      j = 1
      while (j < (size) - i) :
        print(" ", end = "")
        j += 1
      
       # Display star
      j = 0
      while (j <= i) :
        print("*", end = "")
        j += 1
      
      print("\n", end = "")
      i += 1
    
  

def main() :
  obj = MyPattern()
  obj.print_pyramid(5)
  obj.print_pyramid(7)


if __name__ == "__main__":
  main()

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
# Ruby Program
# Left Half Star Pyramid
class MyPattern 
   # Display Pyramid 
  def print_pyramid(size) 
    i = 0
    j = 0
    i = 0
    while (i < size) 
       # Include space in front of star symbol
      j = 1
      while (j < (size) - i) 
        print(" ")
        j += 1
      end
       # Display star
      j = 0
      while (j <= i) 
        print("*")
        j += 1
      end
      print("\n")
      i += 1
    end
  end
end
def main() 
  obj = MyPattern.new()
  obj.print_pyramid(5)
  obj.print_pyramid(7)
end
main()

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
/*
  Scala Program
  Left Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  def print_pyramid(size: Int): Unit = {
    var i: Int = 0;
    var j: Int = 0;
    i = 0;
    while (i < size) {
      //Include space in front of star symbol
      j = 1;
      while (j < (size) - i) {
        print(" ");
        j += 1;
      }
      //Display star
      j = 0;
      while (j <= i) {
        print("*");
        j += 1;
      }
      print("\n");
      i += 1;
    }
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val obj: MyPattern = new MyPattern();
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
/*
  Swift Program
  Left Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  func print_pyramid(_ size: Int) {
    var i: Int = 0;
    var j: Int = 0;
    i = 0;
    while (i < size) {
      //Include space in front of star symbol
      j = 1;
      while (j < (size) - i) {
        print(" ", terminator: "");
        j += 1;
      }
      //Display star
      j = 0;
      while (j <= i) {
        print("*", terminator: "");
        j += 1;
      }
      print(terminator: "\n");
      i += 1;
    }
  }
}
func main() {
  let obj: MyPattern = MyPattern();
  obj.print_pyramid(5);
  obj.print_pyramid(7);
}
main();

Output

    *
   **
  ***
 ****
*****
      *
     **
    ***
   ****
  *****
 ******
*******
/*
  C program 
  Right Half Star Pyramid
*/

#include <stdio.h>
//Display Pyramid 
void print_pyramid(int size)
{

  int i=0,j=0;

  for(i=0; i < size ;i++){
    
    //Display star
    for(j=0;j<=i;j++)
    {
      printf("*");
    }
    
    printf("\n");
  }
}

int main()
{
  //Test Case
  print_pyramid(5);
  print_pyramid(7);
  return 0;
}

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
/*
  C++ Program
  Right Half Star Pyramid
*/
#include<iostream>

using namespace std;

class MyPattern {
  public:

    //Display Pyramid 
    void print_pyramid(int size) {
      int i = 0, j = 0;
      for (i = 0; i < size; i++) {
        //Display star

        for (j = 0; j <= i; j++) {
          cout << "*";
        }
        cout << "\n";
      }
    }
};
int main() {
  MyPattern obj = MyPattern();
  //Test Case
  obj.print_pyramid(5);
  obj.print_pyramid(7);
  return 0;
}

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
/*
  Java Program
  Right Half Star Pyramid
*/

public class MyPattern {
 
  //Display Pyramid 
  public void print_pyramid(int size)
  {

    int i=0,j=0;

    for(i=0; i < size ;i++){
      
      //Display star
      for(j=0;j<=i;j++)
      {
        System.out.print("*");
      }
      
      System.out.print("\n");
    }
  }
  public static void main(String[] args) {

    MyPattern obj = new MyPattern();
    //Test Case
    obj.print_pyramid(5);
    obj.print_pyramid(7);

   
  }
}

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
/*
  C# Program
  Right Half Star Pyramid
*/
using System;

public class MyPattern {
  //Display Pyramid 
  public void print_pyramid(int size) {
    int i = 0, j = 0;
    for (i = 0; i < size; i++) {
      //Display star

      for (j = 0; j <= i; j++) {
        Console.Write("*");
      }
      Console.Write("\n");
    }
  }
  public static void Main(String[] args) {
    MyPattern obj = new MyPattern();
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
<?php
/*
  Php Program
  Right Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 

  public  function print_pyramid($size) {
    $i = 0;
    $j = 0;
    for ($i = 0; $i < $size; $i++) {
      //Display star

      for ($j = 0; $j <= $i; $j++) {
        echo("*");
      }
      echo("\n");
    }
  }
}

function main() {
  $obj = new MyPattern();
  //Test Case

  $obj->print_pyramid(5);
  $obj->print_pyramid(7);

}
main();

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
# Python 3 Program
# Right Half Star Pyramid
class MyPattern :
   # Display Pyramid 
  def print_pyramid(self, size) :
    i = 0
    j = 0
    i = 0
    while (i < size) :
       # Display star
      j = 0
      while (j <= i) :
        print("*", end = "")
        j += 1
      
      print("\n", end = "")
      i += 1
    
  

def main() :
  obj = MyPattern()
  obj.print_pyramid(5)
  obj.print_pyramid(7)


if __name__ == "__main__":
  main()

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
# Ruby Program
# Right Half Star Pyramid
class MyPattern 
   # Display Pyramid 
  def print_pyramid(size) 
    i = 0
    j = 0
    i = 0
    while (i < size) 
       # Display star
      j = 0
      while (j <= i) 
        print("*")
        j += 1
      end
      print("\n")
      i += 1
    end
  end
end
def main() 
  obj = MyPattern.new()
  obj.print_pyramid(5)
  obj.print_pyramid(7)
end
main()

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
/*
  Scala Program
  Right Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  def print_pyramid(size: Int): Unit = {
    var i: Int = 0;
    var j: Int = 0;
    i = 0;
    while (i < size) {
      //Display star
      j = 0;
      while (j <= i) {
        print("*");
        j += 1;
      }
      print("\n");
      i += 1;
    }
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val obj: MyPattern = new MyPattern();
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
/*
  Swift Program
  Right Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  func print_pyramid(_ size: Int) {
    var i: Int = 0;
    var j: Int = 0;
    i = 0;
    while (i < size) {
      //Display star
      j = 0;
      while (j <= i) {
        print("*", terminator: "");
        j += 1;
      }
      print(terminator: "\n");
      i += 1;
    }
  }
}
func main() {
  let obj: MyPattern = MyPattern();
  obj.print_pyramid(5);
  obj.print_pyramid(7);
}
main();

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
/*
  Node Js Program
  Right Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  print_pyramid(size) {
    var i = 0;
    var j = 0;
    i = 0;
    while (i < size) {
      //Display star
      j = 0;
      while (j <= i) {
        process.stdout.write("*");
        j++;
      }

      process.stdout.write("\n");
      i++;
    }
  }
}

function main(args) {
  var obj = new MyPattern();
  obj.print_pyramid(5);
  obj.print_pyramid(7);
}

main();

Output

*
**
***
****
*****
*
**
***
****
*****
******
*******
Inverted Half Star Pyramid
/*
  C program 
  Inverted Left Half Star Pyramid
*/

#include <stdio.h>
//Display Pyramid 
void print_pyramid(int size)
{

  int i=0,j=0;

  for(i=0; i < size ;i++){
    //Include space in front of star symbol
    for(j=0;j<i;j++)
    {
      printf(" ");
    }

    //Display star
    for(j=i;j<size;j++)
    {
      printf("*");
    }
    
    printf("\n");
  }
}

int main()
{
  //Test Case
  print_pyramid(5);
  print_pyramid(7);
  return 0;
}

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
/*
  C++ Program
  Inverted Left Half Star Pyramid
*/
#include<iostream>

using namespace std;


class MyPattern {
  public:

    //Display Pyramid 
    void print_pyramid(int size) {
      int i = 0, j = 0;
      for (i = 0; i < size; i++) {
        //Include space in front of star symbol

        for (j = 0; j < i; j++) {
          cout << " ";
        }
        //Display star

        for (j = i; j < size; j++) {
          cout << "*";
        }
        cout << "\n";
      }
    }
};
int main() {
  MyPattern obj = MyPattern();
  //Test Case
  obj.print_pyramid(5);
  obj.print_pyramid(7);
  return 0;
}

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
/*
  Java Program
  Inverted Left Half Star Pyramid
*/

public class MyPattern {
 
  //Display Pyramid 
  public void print_pyramid(int size)
  {

    int i=0,j=0;

    for(i=0; i < size ;i++){
      //Include space in front of star symbol
      for(j=0;j<i;j++)
      {
        System.out.print(" ");
      }

      //Display star
      for(j=i;j<size;j++)
      {
        System.out.print("*");
      }
      
      System.out.print("\n");
    }
  }
  public static void main(String[] args) {

    MyPattern obj = new MyPattern();
    //Test Case
    obj.print_pyramid(5);
    obj.print_pyramid(7);

   
  }
}

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
/*
  C# Program
  Inverted Left Half Star Pyramid
*/
using System;

public class MyPattern {
  //Display Pyramid 
  public void print_pyramid(int size) {
    int i = 0, j = 0;
    for (i = 0; i < size; i++) {
      //Include space in front of star symbol

      for (j = 0; j < i; j++) {
        Console.Write(" ");
      }
      //Display star

      for (j = i; j < size; j++) {
        Console.Write("*");
      }
      Console.Write("\n");
    }
  }
  public static void Main(String[] args) {
    MyPattern obj = new MyPattern();
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
<?php
/*
  Php Program
  Inverted Left Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 

  public  function print_pyramid($size) {
    $i = 0;
    $j = 0;
    for ($i = 0; $i < $size; $i++) {
      //Include space in front of star symbol

      for ($j = 0; $j < $i; $j++) {
        echo(" ");
      }
      //Display star

      for ($j = $i; $j < $size; $j++) {
        echo("*");
      }
      echo("\n");
    }
  }
}

function main() {
  $obj = new MyPattern();
  //Test Case

  $obj->print_pyramid(5);
  $obj->print_pyramid(7);

}
main();

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
/*
  Node Js Program
  Inverted Left Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  print_pyramid(size) {
    var i = 0;
    var j = 0;
    for (i = 0; i < size; i++) {
      //Include space in front of star symbol

      for (j = 0; j < i; j++) {
        process.stdout.write(" ");
      }

      //Display star

      for (j = i; j < size; j++) {
        process.stdout.write("*");
      }

      process.stdout.write("\n");
    }
  }
}

function main(args) {
  var obj = new MyPattern();
  //Test Case
  obj.print_pyramid(5);
  obj.print_pyramid(7);
}

main();

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
# Python 3 Program
# Inverted Left Half Star Pyramid
class MyPattern :
   # Display Pyramid 
  def print_pyramid(self, size) :
    i = 0
    j = 0
    i = 0
    while (i < size) :
       # Include space in front of star symbol
      j = 0
      while (j < i) :
        print(" ", end = "")
        j += 1
      
       # Display star
      j = i
      while (j < size) :
        print("*", end = "")
        j += 1
      
      print("\n", end = "")
      i += 1
    
  

def main() :
  obj = MyPattern()
  obj.print_pyramid(5)
  obj.print_pyramid(7)


if __name__ == "__main__":
  main()

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
# Ruby Program
# Inverted Left Half Star Pyramid
class MyPattern 
   # Display Pyramid 
  def print_pyramid(size) 
    i = 0
    j = 0
    i = 0
    while (i < size) 
       # Include space in front of star symbol
      j = 0
      while (j < i) 
        print(" ")
        j += 1
      end
       # Display star
      j = i
      while (j < size) 
        print("*")
        j += 1
      end
      print("\n")
      i += 1
    end
  end
end
def main() 
  obj = MyPattern.new()
  obj.print_pyramid(5)
  obj.print_pyramid(7)
end
main()

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
/*
  Scala Program
  Inverted Left Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  def print_pyramid(size: Int): Unit = {
    var i: Int = 0;
    var j: Int = 0;
    i = 0;
    while (i < size) {
      //Include space in front of star symbol
      j = 0;
      while (j < i) {
        print(" ");
        j += 1;
      }
      //Display star
      j = i;
      while (j < size) {
        print("*");
        j += 1;
      }
      print("\n");
      i += 1;
    }
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val obj: MyPattern = new MyPattern();
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
/*
  Swift Program
  Inverted Left Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  func print_pyramid(_ size: Int) {
    var i: Int = 0;
    var j: Int = 0;
    i = 0;
    while (i < size) {
      //Include space in front of star symbol
      j = 0;
      while (j < i) {
        print(" ", terminator: "");
        j += 1;
      }
      //Display star
      j = i;
      while (j < size) {
        print("*", terminator: "");
        j += 1;
      }
      print("\n", terminator: "");
      i += 1;
    }
  }
}
func main() {
  let obj: MyPattern = MyPattern();
  obj.print_pyramid(5);
  obj.print_pyramid(7);
}
main();

Output

*****
 ****
  ***
   **
    *
*******
 ******
  *****
   ****
    ***
     **
      *
/*
  C program 
  Inverted Right Half Star Pyramid
*/

#include <stdio.h>
//Display Pyramid 
void print_pyramid(int size)
{

  int i=0,j=0;

  for(i=0; i < size ;i++){

    //Display star
    for(j=i;j<size;j++)
    {
      printf("*");
    }
    
    printf("\n");
  }
}

int main()
{
  //Test Case
  print_pyramid(5);
  print_pyramid(7);
  return 0;
}

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
/*
  C++ Program
  Inverted Right Half Star Pyramid
*/
#include<iostream>
using namespace std;

class MyPattern {
  public:

    //Display Pyramid 
    void print_pyramid(int size) {
      int i = 0, j = 0;
      for (i = 0; i < size; i++) {
        //Display star

        for (j = i; j < size; j++) {
          cout << "*";
        }
        cout << "\n";
      }
    }
};
int main() {
  MyPattern obj = MyPattern();
  //Test Case
  obj.print_pyramid(5);
  obj.print_pyramid(7);
  return 0;
}

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
/*
  Java Program
  Inverted Right Half Star Pyramid
*/

public class MyPattern {
 
  //Display Pyramid 
  public void print_pyramid(int size)
  {

    int i=0,j=0;

    for(i=0; i < size ;i++){
      //Display star
      for(j=i;j<size;j++)
      {
        System.out.print("*");
      }
      
      System.out.print("\n");
    }
  }
  public static void main(String[] args) {

    MyPattern obj = new MyPattern();
    //Test Case
    obj.print_pyramid(5);
    obj.print_pyramid(7);

   
  }
}

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
/*
  C# Program
  Inverted Right Half Star Pyramid
*/
using System;

public class MyPattern {
  //Display Pyramid 
  public void print_pyramid(int size) {
    int i = 0, j = 0;
    for (i = 0; i < size; i++) {
      //Display star

      for (j = i; j < size; j++) {
        Console.Write("*");
      }
      Console.Write("\n");
    }
  }
  public static void Main(String[] args) {
    MyPattern obj = new MyPattern();
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
<?php
/*
  Php Program
  Inverted Right Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 

  public  function print_pyramid($size) {
    $i = 0;
    $j = 0;
    for ($i = 0; $i < $size; $i++) {
      //Display star

      for ($j = $i; $j < $size; $j++) {
        echo("*");
      }
      echo("\n");
    }
  }
}

function main() {
  $obj = new MyPattern();
  //Test Case

  $obj->print_pyramid(5);
  $obj->print_pyramid(7);

}
main();

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
/*
  Node Js Program
  Inverted Right Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  print_pyramid(size) {
    var i = 0;
    var j = 0;
    for (i = 0; i < size; i++) {
      //Display star

      for (j = i; j < size; j++) {
        process.stdout.write("*");
      }

      process.stdout.write("\n");
    }
  }
}

function main(args) {
  var obj = new MyPattern();
  //Test Case
  obj.print_pyramid(5);
  obj.print_pyramid(7);
}

main();

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
# Python 3 Program
# Inverted Right Half Star Pyramid
class MyPattern :
   # Display Pyramid 
  def print_pyramid(self, size) :
    i = 0
    j = 0
    i = 0
    while (i < size) :
       # Display star
      j = i
      while (j < size) :
        print("*", end = "")
        j += 1
      
      print("\n", end = "")
      i += 1
    
  

def main() :
  obj = MyPattern()
  obj.print_pyramid(5)
  obj.print_pyramid(7)


if __name__ == "__main__":
  main()

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
# Ruby Program
# Inverted Right Half Star Pyramid
class MyPattern 
   # Display Pyramid 
  def print_pyramid(size) 
    i = 0
    j = 0
    i = 0
    while (i < size) 
       # Display star
      j = i
      while (j < size) 
        print("*")
        j += 1
      end
      print("\n")
      i += 1
    end
  end
end
def main() 
  obj = MyPattern.new()
  obj.print_pyramid(5)
  obj.print_pyramid(7)
end
main()

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
/*
  Scala Program
  Inverted Right Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  def print_pyramid(size: Int): Unit = {
    var i: Int = 0;
    var j: Int = 0;

    while (i < size) {
      //Display star
      j = i;
      while (j < size) {
        print("*");
        j += 1;
      }
      print("\n");
      i += 1;
    }
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val obj: MyPattern = new MyPattern();
    obj.print_pyramid(5);
    obj.print_pyramid(7);
  }
}

Output

*****
****
***
**
*
*******
******
*****
****
***
**
*
/*
  Swift Program
  Inverted Right Half Star Pyramid
*/
class MyPattern {
  //Display Pyramid 
  func print_pyramid(_ size: Int) {
    var i: Int = 0;
    var j: Int = 0;
    while (i < size) {
      //Display star
      j = i;
      while (j < size) {
        print("*", terminator: "");
        j += 1;
      }
      print("\n", terminator: "");
      i += 1;
    }
  }
}
func main() {
  let obj: MyPattern = MyPattern();
  obj.print_pyramid(5);
  obj.print_pyramid(7);
}
main();

Output

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


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved