How do you print a hollow pattern in python?

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    Hollow rectangle star pattern :

    The task is print below hollow pattern of given dimension. 
     

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

    Explanation: 
     

    • Input number of rows and columns.
    • For rows of rectangle run the outer loop from 1 to rows. 
       
    for [i = 1; i < = rows; i++]
    • For column of rectangle run the inner loop from 1 to columns. 
       
    for [j = 1; j < = columns; j++]
    • Print star for first or last row or for first or last column, otherwise print blank space.
    • After printing all columns of a row, print new line after inner loop.

    C++

    #include

    using namespace std;

    void print_rectangle[int n, int m]

    {

        int i, j;

        for [i = 1; i

    Javascript

          function print_rectangle[n, m]

          {

            var i, j;

            for [i = 1; i

    Javascript

    Javascript   

        function print_square[int n]

        {

            var i, j;

            for [i = 1; i

    Chủ Đề