Python

Python Program to Print Number Reduction Pattern

Don’t miss the chance of Java programs examples with output pdf free download as it is very essential for all beginners to experienced programmers for cracking the interviews.

Given the number of rows, the task is to print Number Reduction Pattern in C, C++, and Python

Examples:

Example1:

Input:

Given number of rows = 4

Output:

1 2 3 4 
2 3 4 
3 4 
4

Example2:

Input:

Given number of rows = 14

Output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 
2 3 4 5 6 7 8 9 10 11 12 13 14 
3 4 5 6 7 8 9 10 11 12 13 14 
4 5 6 7 8 9 10 11 12 13 14 
5 6 7 8 9 10 11 12 13 14 
6 7 8 9 10 11 12 13 14 
7 8 9 10 11 12 13 14 
8 9 10 11 12 13 14 
9 10 11 12 13 14 
10 11 12 13 14 
11 12 13 14 
12 13 14 
13 14 
14 

Program to Print Number Reduction Pattern in C, C++, and Python

Below are the ways to print Number Reduction Pattern in C, C++, and Python

Method #1: Using For Loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 0 to the number of rows using For loop.
  • Loop from iterator value of the parent For loop +1 to the number of rows using another for loop(Nested For loop).
  • Print the iterator value of the inner for loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

1) Python Implementation

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbrrows = 9
# Loop from 0 to the number of rows using For loop.
for m in range(0, numbrrows+1):
    # Loop from iterator value of the parent For loop +1 to
    # the number of rows using another for loop(Nested For loop).
    for n in range(m + 1, numbrrows+1):
        # Print the iterator value of the inner for loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 2 3 4 5 6 7 8 9 
2 3 4 5 6 7 8 9 
3 4 5 6 7 8 9 
4 5 6 7 8 9 
5 6 7 8 9 
6 7 8 9 
7 8 9 
8 9 
9

2) C++ Implementation

Below is the implementation:

#include <iostream>
using namespace std;

int main()
{

    // Give the number of rows as static input and store it
    // in a variable.
    int numbrrows = 10;
    // Loop from 0 to the number of rows using For loop.
    for (int m = 0; m <= numbrrows; m++) {
        /* Loop from iterator value of the parent For loop+1
           to the number of rows using another for
           loop(Nested For loop).*/
        for (int n = m + 1; n <= numbrrows; n++) {
            // Print the iterator value of the inner for
            // loop.
            cout << n << " ";
        }
        // Print the Newline character after the end of the
        // inner loop.
        cout << endl;
    }
    return 0;
}

Output:

1 2 3 4 5 6 7 8 9 10 
2 3 4 5 6 7 8 9 10 
3 4 5 6 7 8 9 10 
4 5 6 7 8 9 10 
5 6 7 8 9 10 
6 7 8 9 10 
7 8 9 10 
8 9 10 
9 10 
10

3) C Implementation

Below is the implementation:

#include <stdio.h>

int main()
{

    // Give the number of rows as static input and store it
    // in a variable.
    int numbrrows = 14;
    // Loop from 0 to the number of rows using For loop.
    for (int m = 0; m <= numbrrows; m++) {
        /* Loop from iterator value of the parent For loop+1
           to the number of rows using another for
           loop(Nested For loop).*/
        for (int n = m + 1; n <= numbrrows; n++) {
            // Print the iterator value of the inner for
            // loop.
            printf("%d ", n);
        }
        // Print the Newline character after the end of the
        // inner loop.
        printf("\n");
    }
    return 0;
}

Output:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 
2 3 4 5 6 7 8 9 10 11 12 13 14 
3 4 5 6 7 8 9 10 11 12 13 14 
4 5 6 7 8 9 10 11 12 13 14 
5 6 7 8 9 10 11 12 13 14 
6 7 8 9 10 11 12 13 14 
7 8 9 10 11 12 13 14 
8 9 10 11 12 13 14 
9 10 11 12 13 14 
10 11 12 13 14 
11 12 13 14 
12 13 14 
13 14 
14 

Method #2: Using For Loop (User Input)

Approach:

  • Give the number of rows as user input and store it in a variable.
  • Loop from 0 to the number of rows using For loop.
  • Loop from iterator value of the parent For loop +1 to the number of rows using another for loop(Nested For loop).
  • Print the iterator value of the inner for loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

1) Python Implementation

Give the number of rows as user input using int(input()) and store it in a variable.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbrrows = int(input('Enter some random number of rows = '))
# Loop from 0 to the number of rows using For loop.
for m in range(0, numbrrows+1):
    # Loop from iterator value of the parent For loop +1 to
    # the number of rows using another for loop(Nested For loop).
    for n in range(m + 1, numbrrows+1):
        # Print the iterator value of the inner for loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 6
1 2 3 4 5 6 
2 3 4 5 6 
3 4 5 6 
4 5 6 
5 6 
6

2) C++ Implementation

Give the number of rows as user input using cin and store it in a variable.

Below is the implementation:

#include <iostream>
using namespace std;
int main()
{

    // Give the number of rows as user input using
    // int(input()) and store it in a variable.
    int numbrrows;
    cin >> numbrrows;
    // Loop from 0 to the number of rows using For loop.
    for (int m = 0; m <= numbrrows; m++) {
        /* Loop from iterator value of the parent For loop+1
           to the number of rows using another for
           loop(Nested For loop).*/
        for (int n = m + 1; n <= numbrrows; n++) {
            // Print the iterator value of the inner for
            // loop.
            cout << n << " ";
        }
        // Print the Newline character after the end of the
        // inner loop.
        cout << endl;
    }

    return 0;
}

Output:

4
1 2 3 4 
2 3 4 
3 4 
4

3) C Implementation

Give the number of rows as user input using scanf and store it in a variable.

Below is the implementation:

#include <math.h>
#include <stdio.h>
int main()
{

    // Give the number of rows as user input using scanf and
    // store it in a variable.
    int numbrrows;
    scanf("%d", &numbrrows);
    // Loop from 0 to the number of rows using For loop.
    for (int m = 0; m <= numbrrows; m++) {
        /* Loop from iterator value of the parent For loop+1
           to the number of rows using another for
           loop(Nested For loop).*/
        for (int n = m + 1; n <= numbrrows; n++) {
            // Print the iterator value of the inner for
            // loop.
            printf("%d ", n);
        }
        // Print the Newline character after the end of the
        // inner loop.
        printf("\n");
    }
    return 0;
}

Output:

4
1 2 3 4 
2 3 4 
3 4 
4

Related Programs:

Python Program to Print Number Reduction Pattern Read More »

Python Program to Print Reverse Pyramid of Numbers

Are you new to the java programming language? We recommend you to ace up your practice session with these Basic Java Programs Examples

Given the number of rows of the pyramid, the task is to print a Reverse Pyramid of Numbers in C, C++, and Python.

Examples:

Example1:

Input:

Given number of rows = 10

Output:

1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 1

Example2:

Input:

Given number of rows = 6

Output:

1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1

Program to Print Reverse Pyramid of Numbers in C,C++, and Python

Method #1: Using For Loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the parent loop iterator value to 0 in decreasing order using another For loop(Nested For Loop).
  • Print the iterator value of the inner for loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

1) Python Implementation

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbrrows = 10
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbrrows):
    # Loop from the parent loop iterator value to 0 in decreasing order
    # using another For loop(Nested For Loop).
    for n in range(m, 0, -1):
        # Print the iterator value of the inner for loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 1

2) C++ Implementation

Below is the implementation:

#include <iostream>
using namespace std;

int main()
{

    // Give the number of rows as static input and store it
    // in a variable.
    int numbrrows = 10;
    // Loop from 1 to the number of rows using For loop.
    for (int m = 1; m < numbrrows; m++) {
        // Loop from the parent loop iterator value to 0 in
        // decreasing order using another For loop(Nested
        // For Loop).
        for (int n = m; n > 0; n--) {
            // Print the iterator value of the inner for
            // loop.
            cout << n << " ";
        }
        // Print the Newline character after the end of the
        // inner loop.
        cout << endl;
    }

    return 0;
}

Output:

1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 1

3) C Implementation

Below is the implementation:

#include <stdio.h>

int main()
{

    // Give the number of rows as static input and store it
    // in a variable.
    int numbrrows = 10;
    // Loop from 1 to the number of rows using For loop.
    for (int m = 1; m < numbrrows; m++) {
        // Loop from the parent loop iterator value to 0 in
        // decreasing order using another For loop(Nested
        // For Loop).
        for (int n = m; n > 0; n--) {
            // Print the iterator value of the inner for
            // loop.
            printf("%d ", n);
        }
        // Print the Newline character after the end of the
        // inner loop.
        printf("\n");
    }
    return 0;
}

Output:

1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 1

Method #2: Using For Loop (User Input)

Approach:

  • Give the number of rows as user input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the parent loop iterator value to 0 in decreasing order using another For loop(Nested For Loop).
  • Print the iterator value of the inner for loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

1) Python Implementation

Give the number of rows as user input using int(input()) and store it in a variable.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbrrows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbrrows):
    # Loop from the parent loop iterator value to 0 in decreasing order
    # using another For loop(Nested For Loop).
    for n in range(m, 0, -1):
        # Print the iterator value of the inner for loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 6
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1

2) C++ Implementation

Give the number of rows as user input using cin and store it in a variable.

Below is the implementation:

#include <iostream>
using namespace std;

int main()
{

    // Give the number of rows as user input using
    // cin and store it in a variable.
    int numbrrows;
    cin >> numbrrows;
    // Loop from 1 to the number of rows using For loop.
    for (int m = 1; m < numbrrows; m++) {
        // Loop from the parent loop iterator value to 0 in
        // decreasing order using another For loop(Nested
        // For Loop).
        for (int n = m; n > 0; n--) {
            // Print the iterator value of the inner for
            // loop.
            cout << n << " ";
        }
        // Print the Newline character after the end of the
        // inner loop.
        cout << endl;
    }

    return 0;
}

Output:

6
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1

3) C Implementation

Give the number of rows as user input using scanf and store it in a variable.

Below is the implementation:

#include <stdio.h>

int main()
{

    // Give the number of rows as user input using scanf and
    // store it in a variable.
    int numbrrows;
    scanf("%d", &numbrrows);
    // Loop from 1 to the number of rows using For loop.
    for (int m = 1; m < numbrrows; m++) {
        // Loop from the parent loop iterator value to 0 in
        // decreasing order using another For loop(Nested
        // For Loop).
        for (int n = m; n > 0; n--) {
            // Print the iterator value of the inner for
            // loop.
            printf("%d ", n);
        }
        // Print the Newline character after the end of the
        // inner loop.
        printf("\n");
    }
    return 0;
}

Output:

6
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1

Related Programs:

Python Program to Print Reverse Pyramid of Numbers Read More »

Number Pattern Programs in Python

If you are new to Java and want to learn the java coding skills too fast. Try practicing the core java programs with the help of the Java basic programs list available.

1) Number Pattern – 1

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For Loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For Loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 8
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8

2) Number Pattern – 2

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For Loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • Loop from the number of rows-1 to 1 in decreasing order using For loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 6
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()
# Loop from the number of rows-1 to 1 in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For Loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • Loop from the number of rows-1 to 1 in decreasing order using For loop.
  • Loop from 1 to iterator value of the parent For loop using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()
# Loop from the number of rows-1 to 1 in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 8
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

3) Number Pattern – 3

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the parent loop with space in the inner For loop. (This prints the same number parent loop number of times)
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the nested loop with space in the inner For loop.
        # (This prints the same number parent loop number of times)
        print(m, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6 
7 7 7 7 7 7 7 
8 8 8 8 8 8 8 8

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the parent loop with space in the inner For loop. (This prints the same number parent loop number of times)
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the nested loop with space in the inner For loop.
        # (This prints the same number parent loop number of times)
        print(m, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 6
1 
2 2 
3 3 3 
4 4 4 4 
5 5 5 5 5 
6 6 6 6 6 6

4) Number Pattern – 4

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to iterator value>=m in decreasing order using another For Loop(Inner For loop) where m is the iterator value of the parent For loop.
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 10
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to iterator value>=m in decreasing order
    # using another For Loop(Inner For loop)
    # where m is the iterator value of the parent For loop.
    for n in range(numbOfRows, m-1, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

10 9 8 7 6 5 4 3 2 1 
10 9 8 7 6 5 4 3 2 
10 9 8 7 6 5 4 3 
10 9 8 7 6 5 4 
10 9 8 7 6 5 
10 9 8 7 6 
10 9 8 7 
10 9 8 
10 9 
10

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to m in decreasing order using another For Loop(Inner For loop) where m is the iterator value of the parent For loop.
  • Print the iterator value of the inner For loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to iterator value>=m in decreasing order
    # using another For Loop(Inner For loop)
    # where m is the iterator value of the parent For loop.
    for n in range(numbOfRows, m-1, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 9
9 8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 
9 8 7 6 5 4 3 
9 8 7 6 5 4 
9 8 7 6 5 
9 8 7 6 
9 8 7 
9 8 
9

5) Number Pattern – 5

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 5
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1

6) Number Pattern – 6

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 11
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from iterator value of the parent For loop to 1(included)
    # in decreasing order using another Nested For loop.
    for n in range(m, 0, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

11 10 9 8 7 6 5 4 3 2 1 
10 9 8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from iterator value of the parent For loop to 1(included)
    # in decreasing order using another Nested For loop.
    for n in range(m, 0, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 8
8 7 6 5 4 3 2 1 
7 6 5 4 3 2 1 
6 5 4 3 2 1 
5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1

7) Number Pattern – 7

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from the number of rows to m in decreasing order using another For Loop(Inner For loop) where m is the iterator value of the parent For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows =6
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from the number of rows to m in decreasing order using
    # another For Loop(Inner For loop)
    # where m is the iterator value of the parent For loop.
    for n in range(numbOfRows, m-1, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

6 
6 5 
6 5 4 
6 5 4 3 
6 5 4 3 2 
6 5 4 3 2 1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

Output:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from the number of rows to m in decreasing order using
    # another For Loop(Inner For loop)
    # where m is the iterator value of the parent For loop.
    for n in range(numbOfRows, m-1, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 8
8 
8 7 
8 7 6 
8 7 6 5 
8 7 6 5 4 
8 7 6 5 4 3 
8 7 6 5 4 3 2 
8 7 6 5 4 3 2 1

8) Number Pattern – 8

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from iterator value of the parent For loop -1 to 1(included) in decreasing order using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    '''Loop from iterator value of the parent For loop -1 to 1(included) 
    in decreasing order using another For loop(Inner For Loop). '''
    for n in range(m-1, 0, -1):
       # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print(

Output:

1 
1 2 1 
1 2 3 2 1 
1 2 3 4 3 2 1 
1 2 3 4 5 4 3 2 1 
1 2 3 4 5 6 5 4 3 2 1 
1 2 3 4 5 6 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from iterator value of the parent For loop -1 to 1(included) in decreasing order using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    '''Loop from iterator value of the parent For loop -1 to 1(included) 
    in decreasing order using another For loop(Inner For Loop). '''
    for n in range(m-1, 0, -1):
       # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 10
1 
1 2 1 
1 2 3 2 1 
1 2 3 4 3 2 1 
1 2 3 4 5 4 3 2 1 
1 2 3 4 5 6 5 4 3 2 1 
1 2 3 4 5 6 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 
1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1

9) Number Pattern – 9

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from 2 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()
# Loop from 2 to the number of rows using For Loop.
for m in range(2, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from 2 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()
# Loop from 2 to the number of rows using For Loop.
for m in range(2, numbOfRows+1):
    # Loop from 1 to iterator value of the parent For loop
    # using another For loop(Inner For Loop).
    for n in range(1, m+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 11
1 2 3 4 5 6 7 8 9 10 11 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 
1 2 3 4 5 6 
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 
1 2 3 4 5 6 
1 2 3 4 5 6 7 
1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9 10 
1 2 3 4 5 6 7 8 9 10 11

10) Number Pattern – 10

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print Two spaces.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print Two spaces.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print Two spaces.
        print(' ', end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

# Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print Two spaces.
        print(' ', end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1 2 3 4 5 6 7 8 
   2 3 4 5 6 7 8 
      3 4 5 6 7 8 
         4 5 6 7 8 
            5 6 7 8 
               6 7 8 
                  7 8 
                     8 
                  7 8 
               6 7 8 
            5 6 7 8 
         4 5 6 7 8  
      3 4 5 6 7 8  
   2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print Two spaces.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print Two spaces.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print Two spaces.
        print(' ', end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

# Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print Two spaces.
        print(' ', end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 8
1 2 3 4 5 6 7 8 
   2 3 4 5 6 7 8 
      3 4 5 6 7 8 
         4 5 6 7 8 
            5 6 7 8 
               6 7 8 
                  7 8 
                     8 
                  7 8 
               6 7 8 
            5 6 7 8 
         4 5 6 7 8  
      3 4 5 6 7 8  
   2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8

11) Number Pattern – 11

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 10
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from iterator value of the parent For loop to 1(included)
    # in decreasing order
    # using another Nested For loop.
    for n in range(m, 0, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1 
8 7 6 5 4 3 2 1 
9 8 7 6 5 4 3 2 1 
10 9 8 7 6 5 4 3 2 1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from iterator value of the parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from iterator value of the parent For loop to 1(included)
    # in decreasing order
    # using another Nested For loop.
    for n in range(m, 0, -1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 7
1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1 
6 5 4 3 2 1 
7 6 5 4 3 2 1

12) Number Pattern – 12

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Check if the iterator value of the inner For loop is divisible by 2 or not using the If statement.
  • If it is true then print 0.
  • Else print 1.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Check if the iterator value of the inner For loop is divisible by 2
        # or not using the If statement.
        if(n % 2 == 0):
            # If it is true then print 0.
            print('0', end='')
           # Else print 1.
        else:
            print('1', end='')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1
10
101
1010
10101
101010
1010101
10101010

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Check if the iterator value of the inner For loop is divisible by 2 or not using the If statement.
  • If it is true then print 0.
  • Else print 1.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Check if the iterator value of the inner For loop is divisible by 2
        # or not using the If statement.
        if(n % 2 == 0):
            # If it is true then print 0.
            print('0', end='')
           # Else print 1.
        else:
            print('1', end='')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 11
1
10
101
1010
10101
101010
1010101
10101010
101010101
1010101010
10101010101

13) Number Pattern – 13

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to the number of rows using another Nested For loop.
  • Check if the iterator value of the inner For loop is equal to the iterator value of the parent For loop or not using the If statement.
  • If it is true then print the iterator value of the inner For Loop.
  • Else print 0.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to the number of rows using another Nested For loop.
    for n in range(1, numbOfRows+1):
        # Check if the iterator value of the inner For loop is equal to the iterator value of the parent
        # For loop or not using the If statement.
        if(n == m):
            # If it is true then print n.
            print(n, end=' ')
           # Else print 0.
        else:
            print('0', end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1 0 0 0 0 0 0 0 
0 2 0 0 0 0 0 0 
0 0 3 0 0 0 0 0 
0 0 0 4 0 0 0 0 
0 0 0 0 5 0 0 0 
0 0 0 0 0 6 0 0 
0 0 0 0 0 0 7 0 
0 0 0 0 0 0 0 8

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from 1 to the number of rows using another Nested For loop.
  • Check if the iterator value of the inner For loop is equal to the iterator value of the parent For loop or not using the If statement.
  • If it is true then print the iterator value of the inner For Loop.
  • Else print 0.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to the number of rows using another Nested For loop.
    for n in range(1, numbOfRows+1):
        # Check if the iterator value of the inner For loop is equal to the iterator value of the parent
        # For loop or not using the If statement.
        if(n == m):
            # If it is true then print n.
            print(n, end=' ')
           # Else print 0.
        else:
            print('0', end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 6
1 0 0 0 0 0 
0 2 0 0 0 0 
0 0 3 0 0 0 
0 0 0 4 0 0 
0 0 0 0 5 0 
0 0 0 0 0 6

14) Number Pattern – 14

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the space character.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the space character.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 6
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the space character.
        print(end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

# Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the space character.
        print(end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1 2 3 4 5 6 
 2 3 4 5 6 
  3 4 5 6 
   4 5 6 
    5 6 
     6 
    5 6 
   4 5 6 
  3 4 5 6 
 2 3 4 5 6 
1 2 3 4 5 6

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the space character.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the space character.
  • Loop from the first loop iterator value to the number of rows(included) using Another For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the space character.
        print(end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

# Loop from the number of rows -1 to 1(included) in decreasing order using For loop.
for m in range(numbOfRows-1, 0, -1):
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the space character.
        print(end=' ')
    # Loop from the first loop iterator value to the number of rows(included)
    # using Another For loop.
    for n in range(m, numbOfRows+1):
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 8
1 2 3 4 5 6 7 
 2 3 4 5 6 7 
  3 4 5 6 7 
   4 5 6 7 
    5 6 7 
     6 7 
      7 
     6 7 
    5 6 7 
   4 5 6 7 
  3 4 5 6 7 
 2 3 4 5 6 7 
1 2 3 4 5 6 7

15) Number Pattern – 15

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to the number of rows -first loop iterator value using another Nested For loop.
  • Print 1.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the parent For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to the number of rows -first loop iterator
    # value using another Nested For loop.
    for n in range(1, numbOfRows-m+1):
        # Print 1.
        print('1', end=' ')

    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the iterator value of the parent For loop.
        print(m, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 2 
1 1 1 1 1 1 3 3 
1 1 1 1 1 4 4 4 
1 1 1 1 5 5 5 5 
1 1 1 6 6 6 6 6 
1 1 7 7 7 7 7 7 
1 8 8 8 8 8 8 8 
9 9 9 9 9 9 9 9

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from 1 to the number of rows -first loop iterator value using another Nested For loop.
  • Print 1.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the parent For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from 1 to the number of rows -first loop iterator
    # value using another Nested For loop.
    for n in range(1, numbOfRows-m+1):
        # Print 1.
        print('1', end=' ')

    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the iterator value of the parent For loop.
        print(m, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 6
1 1 1 1 1 
1 1 1 1 2 
1 1 1 3 3 
1 1 4 4 4 
1 5 5 5 5 
6 6 6 6 6

16) Number Pattern – 16

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from the iterator value of the parent For loop to the number of rows using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from the iterator value of the parent For loop to the number of rows
    # using another Nested For loop.
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1 2 3 4 5 6 7 8 9 
2 3 4 5 6 7 8 9 1 
3 4 5 6 7 8 9 1 2 
4 5 6 7 8 9 1 2 3 
5 6 7 8 9 1 2 3 4 
6 7 8 9 1 2 3 4 5 
7 8 9 1 2 3 4 5 6 
8 9 1 2 3 4 5 6 7 
9 1 2 3 4 5 6 7 8

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the 1 to the number of rows using For loop.
  • Loop from the iterator value of the parent For loop to the number of rows using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Loop from the iterator value of the parent For loop to the number of rows
    # using another Nested For loop.
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 11
1 2 3 4 5 6 7 8 9 10 11 
2 3 4 5 6 7 8 9 10 11 1 
3 4 5 6 7 8 9 10 11 1 2 
4 5 6 7 8 9 10 11 1 2 3 
5 6 7 8 9 10 11 1 2 3 4 
6 7 8 9 10 11 1 2 3 4 5 
7 8 9 10 11 1 2 3 4 5 6 
8 9 10 11 1 2 3 4 5 6 7 
9 10 11 1 2 3 4 5 6 7 8 
10 11 1 2 3 4 5 6 7 8 9 
11 1 2 3 4 5 6 7 8 9 10

17) Number Pattern – 17

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Take a variable and initialize it with 1 say sampNumber.
  • Loop from 1 to the number of rows of the triangle using For loop.
  • Using another For loop, loop from 1 to the parent loop iterator value (Nested For loop).
  • Inside the inner for loop print the sampNumber with a space character.
  • Increase the value of sampNum by 1.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows of the triangle as static input and store it in a variable.
numbOfRows = 4
# Take a variable and initialize it with 1 say sampNumber.
sampNumber = 1
# Loop from 1 to the number of rows of the triangle using For loop.
for m in range(1, numbOfRows+1):
  # Using another For loop, loop from 1 to the parent loop iterator value (Nested For loop).
    for n in range(1, m+1):
        # Inside the inner for loop print the sampNumber with a space character.
        print(sampNumber, end=' ')
        # Increase the value of sampNumber by 1.
        sampNumber = sampNumber+1
    # Print the Newline Character after the end of the inner for loop.
    print()

Output:

1 
2 3 
4 5 6 
7 8 9 10

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Take a variable and initialize it with 1 say sampNumber.
  • Loop from 1 to the number of rows of the triangle using For loop.
  • Using another For loop, loop from 1 to the parent loop iterator value (Nested For loop).
  • Inside the inner for loop print the sampNumber with a space character.
  • Increase the value of sampNum by 1.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Take a variable and initialize it with 1 say sampNumber.
sampNumber = 1
# Loop from 1 to the number of rows of the triangle using For loop.
for m in range(1, numbOfRows+1):
  # Using another For loop, loop from 1 to the parent loop iterator value (Nested For loop).
    for n in range(1, m+1):
        # Inside the inner for loop print the sampNumber with a space character.
        print(sampNumber, end=' ')
        # Increase the value of sampNumberby 1.
        sampNumber = sampNumber+1
    # Print the Newline Character after the end of the inner for loop.
    print()

Output:

Enter some random number of rows = 6
1 
2 3 
4 5 6 
7 8 9 10 
11 12 13 14 15 
16 17 18 19 20 21

18) Number Pattern – 18

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Take a variable and initialize its value with the iterator value of the parent For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the samp value.
  • Modify the samp by samp+number of rows – n, where n is the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Take a variable and initialize its value with the
    # iterator value of the parent For loop.
    samp = m
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the samp value.
        print(samp, end=' ')
        # Modify the samp by samp+number of rows - n,
        # where n is the iterator value of the inner For loop.
        samp = samp+numbOfRows-n
    # Print the newline character after ending of inner For loop.
    print()

Output:

1 
2 10 
3 11 18 
4 12 19 25 
5 13 20 26 31 
6 14 21 27 32 36 
7 15 22 28 33 37 40 
8 16 23 29 34 38 41 43 
9 17 24 30 35 39 42 44 45

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Take a variable and initialize its value with the iterator value of the parent For loop.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the samp value.
  • Modify the samp by samp+number of rows – n, where n is the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Take a variable and initialize its value with the
    # iterator value of the parent For loop.
    samp = m
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
        # Print the samp value.
        print(samp, end=' ')
        # Modify the samp by samp+number of rows - n,
        # where n is the iterator value of the inner For loop.
        samp = samp+numbOfRows-n
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 9
1 
2 10 
3 11 18 
4 12 19 25 
5 13 20 26 31 
6 14 21 27 32 36 
7 15 22 28 33 37 40 
8 16 23 29 34 38 41 43 
9 17 24 30 35 39 42 44 45

19) Number Pattern – 19

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows of the triangle using For loop.
  • Take a variable and initialize it with the iterator value of the parent For loop say samp.
  • Loop from iterator value of the Parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Inside the inner for loop print the samp with a space character.
  • Increase the value of samp by the number of rows.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 8
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Take a variable and initialize it with the iterator value of
    # the parent For loop say samp.
    samp = m
    # Loop from iterator value of the Parent For loop to 1(included)
    # in decreasing order using another Nested For loop.
    for n in range(m, 0, -1):
        # Inside the inner for loop print the samp with a space character.
        print(samp, end=' ')
        # Increase the value of samp by the number of rows.
        samp = samp+numbOfRows
    # Print the newline character after ending of inner For loop.
    print()

Output:

1 
2 10 
3 11 19 
4 12 20 28 
5 13 21 29 37 
6 14 22 30 38 46 
7 15 23 31 39 47 55 
8 16 24 32 40 48 56 64

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows of the triangle using For loop.
  • Take a variable and initialize it with the iterator value of the parent For loop say samp.
  • Loop from iterator value of the Parent For loop to 1(included) in decreasing order using another Nested For loop.
  • Inside the inner for loop print the samp with a space character.
  • Increase the value of samp by the number of rows.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbOfRows+1):
    # Take a variable and initialize it with the iterator value of
    # the parent For loop say samp.
    samp = m
    # Loop from iterator value of the Parent For loop to 1(included)
    # in decreasing order using another Nested For loop.
    for n in range(m, 0, -1):
        # Inside the inner for loop print the samp with a space character.
        print(samp, end=' ')
        # Increase the value of samp by the number of rows.
        samp = samp+numbOfRows
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 9
1 
2 11 
3 12 21 
4 13 22 31 
5 14 23 32 41 
6 15 24 33 42 51 
7 16 25 34 43 52 61 
8 17 26 35 44 53 62 71 
9 18 27 36 45 54 63 72 81

20) Number Pattern – 20

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from 1 to iterator value of the parent For loop using another Nested For loop.
  • Inside the inner for loop print the space character.
  • Loop from parent loop iterator value to the number of rows using another For loop(Inner For loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to iterator value of the parent For loop using another Nested For loop.
    for n in range(1, m):
        # Inside the inner for loop print the space character.
        print(end=' ')
    # Loop from parent loop iterator value to the number of rows
    # using another For loop(Inner For loop).
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

        9 
       8 9 
      7 8 9 
     6 7 8 9 
    5 6 7 8 9 
   4 5 6 7 8 9 
  3 4 5 6 7 8 9 
 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from the number of rows to 1(included) in decreasing order using For loop.
  • Loop from 1 to iterator value of the parent For loop using another Nested For loop.
  • Inside the inner for loop print the space character.
  • Loop from parent loop iterator value to the number of rows using another For loop(Inner For loop).
  • Print the iterator value of the inner For loop.
  • Print the Newline Character after the end of the inner for loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from the number of rows to 1(included) in decreasing order using For loop.
for m in range(numbOfRows, 0, -1):
    # Loop from 1 to iterator value of the parent For loop using another Nested For loop.
    for n in range(1, m):
        # Inside the inner for loop print the space character.
        print(end=' ')
    # Loop from parent loop iterator value to the number of rows
    # using another For loop(Inner For loop).
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 9
        9 
       8 9 
      7 8 9 
     6 7 8 9 
    5 6 7 8 9 
   4 5 6 7 8 9 
  3 4 5 6 7 8 9 
 2 3 4 5 6 7 8 9 
1 2 3 4 5 6 7 8 9

21) Number Pattern – 21

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the first loop iterator value to the number of rows using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from the number of rows-1 to iterator value of the parent For loop (included) in decreasing order using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the first loop iterator value
    # to the number of rows using another Nested For loop.
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    '''Loop from the number of rows-1 to iterator value of the parent For loop (included)
    in decreasing order using another For loop(Inner For Loop). '''
    for n in range(numbOfRows-1, m-1, -1):
       # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 
2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 
3 4 5 6 7 8 9 8 7 6 5 4 3 
4 5 6 7 8 9 8 7 6 5 4 
5 6 7 8 9 8 7 6 5 
6 7 8 9 8 7 6 
7 8 9 8 7 
8 9 8 
9

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the first loop iterator value to the number of rows using another Nested For loop.
  • Print the iterator value of the inner For loop.
  • Loop from the number of rows-1 to iterator value of the parent For loop (included) in decreasing order using another For loop(Inner For Loop).
  • Print the iterator value of the inner For loop.
  • Print the newline character after ending of inner For loop.
  • The Exit of the program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the first loop iterator value
    # to the number of rows using another Nested For loop.
    for n in range(m, numbOfRows+1):
        # Print the iterator value of the inner For loop.
        print(n, end=' ')
    '''Loop from the number of rows-1 to iterator value of the parent For loop (included)
    in decreasing order using another For loop(Inner For Loop). '''
    for n in range(numbOfRows-1, m-1, -1):
       # Print the iterator value of the inner For loop.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 13
1 2 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 2 1 
2 3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 2 
3 4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 3 
4 5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 4 
5 6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 5 
6 7 8 9 10 11 12 13 12 11 10 9 8 7 6 
7 8 9 10 11 12 13 12 11 10 9 8 7 
8 9 10 11 12 13 12 11 10 9 8 
9 10 11 12 13 12 11 10 9 
10 11 12 13 12 11 10 
11 12 13 12 11 
12 13 12 
13

22) Number Pattern – 22

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to the iterator value of the parent For loop using another For loop(Inner For loop).
  • Print the space character.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the first loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to the iterator value of the parent
    # For loop using another For loop(Inner For loop).
    for n in range(numbOfRows, m, -1):
        # Print the space character.
        print(end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
       # Print the first loop iterator value.
        print(m, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

        1 
       2 2 
      3 3 3 
     4 4 4 4 
    5 5 5 5 5 
   6 6 6 6 6 6 
  7 7 7 7 7 7 7 
 8 8 8 8 8 8 8 8 
9 9 9 9 9 9 9 9 9

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to the iterator value of the parent For loop using another For loop(Inner For loop).
  • Print the space character.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the first loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to the iterator value of the parent
    # For loop using another For loop(Inner For loop).
    for n in range(numbOfRows, m, -1):
        # Print the space character.
        print(end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
       # Print the first loop iterator value.
        print(m, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 7
      1 
     2 2 
    3 3 3 
   4 4 4 4 
  5 5 5 5 5 
 6 6 6 6 6 6 
7 7 7 7 7 7 7

23) Number Pattern – 23

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 0 to the number of rows using For loop.
  • Loop from 0 to the number of rows using another For loop(Inner For loop).
  • Check if the inner Loop iterator value is divisible by 2 or not using the If statement.
  • If it is divisible then print (number of rows * n)+m+1 Where m is the iterator value of the parent For loop and n is the iterator value of the inner For loop.
  • Else print (number of rows * (n+1) ) -m.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 4
# Loop from 0 to the number of rows using For loop.
for m in range(0, numbOfRows):
    # Loop from 0 to the number of rows using another For loop(Inner For loop).
    for n in range(0, numbOfRows):
        # Check if the inner Loop iterator value is divisible by 2 or not
        # using the If statement.
        if(n % 2 == 0):
            # If it is divisible then print (number of rows * n)+m+1
            # Where m is the iterator value of the parent For loop
            # and n is the iterator value of the inner For loop.
            print((numbOfRows*n)+m+1, end=' ')
        # Else print (number of rows * (n+1) ) -m.
        else:
            print((numbOfRows * (n+1)) - m, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

1 8 9 16 
2 7 10 15 
3 6 11 14 
4 5 12 13

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 0 to the number of rows using For loop.
  • Loop from 0 to the number of rows using another For loop(Inner For loop).
  • Check if the inner Loop iterator value is divisible by 2 or not using the If statement.
  • If it is divisible then print (number of rows * n)+m+1 Where m is the iterator value of the parent For loop and n is the iterator value of the inner For loop.
  • Else print (number of rows * (n+1) ) -m.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 0 to the number of rows using For loop.
for m in range(0, numbOfRows):
    # Loop from 0 to the number of rows using another For loop(Inner For loop).
    for n in range(0, numbOfRows):
        # Check if the inner Loop iterator value is divisible by 2 or not
        # using the If statement.
        if(n % 2 == 0):
            # If it is divisible then print (number of rows * n)+m+1
            # Where m is the iterator value of the parent For loop
            # and n is the iterator value of the inner For loop.
            print((numbOfRows*n)+m+1, end=' ')
        # Else print (number of rows * (n+1) ) -m.
        else:
            print((numbOfRows * (n+1)) - m, end=' ')

    # Print the newline character after ending of inner For loop.
    print()

Output:

Enter some random number of rows = 5
1 10 11 20 21 
2 9 12 19 22 
3 8 13 18 23 
4 7 14 17 24 
5 6 15 16 25

24) Number Pattern – 24

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the iterator value of the parent For loop to the number of rows using another For loop(Inner For loop).
  • Print the inner loop iterator value.
  • Loop from iterator value of the parent For loop-1 to 1(included) in decreasing order using another Inner For loop.
  • Print the inner loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 7
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the iterator value of the parent For loop to the
    # number of rows using another For loop(Inner For loop).
    for n in range(m, numbOfRows+1):
        # Print the inner loop iterator value.
        print(n, end=' ')
    # Loop from iterator value of the parent For loop-1 to 1(included)
    # in decreasing order
    # using another Inner For loop.
    for n in range(m-1, 0, -1):
        # Print the inner loop iterator value
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

1 2 3 4 5 6 7 
2 3 4 5 6 7 1 
3 4 5 6 7 2 1 
4 5 6 7 3 2 1 
5 6 7 4 3 2 1 
6 7 5 4 3 2 1 
7 6 5 4 3 2 1

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the iterator value of the parent For loop to the number of rows using another For loop(Inner For loop).
  • Print the inner loop iterator value.
  • Loop from iterator value of the parent For loop-1 to 1(included) in decreasing order using another Inner For loop.
  • Print the inner loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the iterator value of the parent For loop to the
    # number of rows using another For loop(Inner For loop).
    for n in range(m, numbOfRows+1):
        # Print the inner loop iterator value.
        print(n, end=' ')
    # Loop from iterator value of the parent For loop-1 to 1(included)
    # in decreasing order
    # using another Inner For loop.
    for n in range(m-1, 0, -1):
        # Print the inner loop iterator value
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 8
1 2 3 4 5 6 7 8 
2 3 4 5 6 7 8 1 
3 4 5 6 7 8 2 1 
4 5 6 7 8 3 2 1 
5 6 7 8 4 3 2 1 
6 7 8 5 4 3 2 1 
7 8 6 5 4 3 2 1 
8 7 6 5 4 3 2 1

25) Number Pattern – 25

Method #1: Using For loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to the iterator value of the parent For loop using another For loop(Inner For loop).
  • Print the space character.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the inner loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbOfRows = 9
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to the iterator value of the parent
    # For loop using another For loop(Inner For loop).
    for n in range(numbOfRows, m, -1):
        # Print the space character.
        print(end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
       # Print the inner loop iterator value.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

        1 
       1 2 
      1 2 3 
     1 2 3 4 
    1 2 3 4 5 
   1 2 3 4 5 6 
  1 2 3 4 5 6 7 
 1 2 3 4 5 6 7 8 
1 2 3 4 5 6 7 8 9

Method #2: Using For loop (User Input)

Approach:

  • Give the number of rows as user input using int(input()) and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from the number of rows to the iterator value of the parent For loop using another For loop(Inner For loop).
  • Print the space character.
  • Loop from 1 to first loop iterator value using another Nested For loop.
  • Print the inner loop iterator value.
  • Print the newline character after ending of inner For loop.
  • The Exit of the Program.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbOfRows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For Loop.
for m in range(1, numbOfRows+1):
    # Loop from the number of rows to the iterator value of the parent
    # For loop using another For loop(Inner For loop).
    for n in range(numbOfRows, m, -1):
        # Print the space character.
        print(end=' ')
    # Loop from 1 to first loop iterator value using another Nested For loop.
    for n in range(1, m+1):
       # Print the inner loop iterator value.
        print(n, end=' ')

    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 13
            1 
           1 2 
          1 2 3 
         1 2 3 4 
        1 2 3 4 5 
       1 2 3 4 5 6 
      1 2 3 4 5 6 7 
     1 2 3 4 5 6 7 8 
    1 2 3 4 5 6 7 8 9 
   1 2 3 4 5 6 7 8 9 10 
  1 2 3 4 5 6 7 8 9 10 11 
 1 2 3 4 5 6 7 8 9 10 11 12 
1 2 3 4 5 6 7 8 9 10 11 12 13

Number Pattern Programs in Python Read More »

Python Program to Print Hollow Mirrored Rhombus Star Pattern

Have you mastered basic programming topics of java and looking forward to mastering advanced topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.

Given the number of rows of the Rhombus, the task is to print the Hollow Mirrored Rhombus Star pattern in C, C++, and Python.

Examples:

Example1:

Input:

given number of rows of the rhombus =8

Output:

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

Example2:

Input:

Given number of rows of the rhombus =6
Given character to print ='~'

Output:

6~
~ ~ ~ ~ ~ ~ 
  ~               ~ 
    ~               ~ 
      ~               ~ 
        ~               ~ 
          ~ ~ ~ ~ ~ ~

Program to Print the Hollow Mirrored Rhombus Star Pattern in C, C++, and Python

Below are the ways to print the Hollow mirrored Rhonbus star Patterns in C, C++, and Python.

Method #1: Using For loop (Star Character)

Approach:

  • Give the number of rows of the Hollow rhombus as static input and store it in a variable.
  • Loop till the number of rows of the rhombus using For loop.
  • Iterate till the first iterator using another For loop(Nested For loop).
  • Print the space character in the inner for loop.
  • Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
  • If the parent For loop iterator value is equal to 0 or the number of rows-1, then print star with a space character.
  • If the current iterator’s value is equal to 0 or the number of rows-1, the print star with a space character.
  • Check the above two statements true or false using the If condition statement.
  • If it is true then print star with a space character.
  • Else print space.
  • Print the newline character after the end of two nested for loops.
  • The Exit of the Program.

1) Python Implementation

Below is the implementation:

# Give the number of rows of the rhombus as static input and store it in a variable.
rhombusrows = 8
# Loop till the number of rows of the rhombus using For loop.
for m in range(rhombusrows):
  # Iterate till the first iterator using another For loop(Nested For loop).
    for n in range(m):
      # Print the space character in the inner for loop.
        print(' ', end='')
    # Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
    for o in range(rhombusrows):
      # If the parent For loop iterator value is equal to 0 or the number of rows-1, then print star with a space character.
      # If the current iterator's value is equal to 0 or the number of rows-1, the print star with a space character.
      # Check the above two statements true or false using the If condition statement.
      # If it is true then print star with a space character.
      # Else print space.
        if(m == 0 or m == rhombusrows - 1 or o == 0 or o == rhombusrows - 1):
            print('*', end=' ')
        else:
            print(' ', end=' ')
    # Print the newline character after the end of two nested for loops.
    print()

Output:

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

2) C++ Implementation

Below is the implementation:

#include <iostream>
using namespace std;

int main()
{

    // Give the number of rows of the rhombus as static
    // input and store it in a variable.
    int rhombusrows = 8;
    // Loop till the number of rows of the rhombus using For
    // loop.
    for (int m = 0; m < rhombusrows; m++) {
        // Iterate till the first iterator using another For
        // loop(Nested For loop).

        for (int n = 0; n < m; n++) {
            // Print the space character in the inner for
            // loop.

            cout << "  ";
        }
        // Loop till the number of rows of the rhombus using
        // For loop(Second Nested For loop).
        for (int r = 0; r < rhombusrows; r++) {
            /*If the parent For loop iterator value is equal
              to 0 or the number of rows-1, then print star
              with a space character. If the current
              iterator's value is equal to 0 or the number
              of rows-1, the print star with a space
              character. Check the above two statements true
              or false using the If condition statement. If
              it is true then print star with a space
              character. Else print space.*/
            if (m == 0 || m == rhombusrows - 1 || r == 0 || r == rhombusrows - 1)
                cout << "* ";
            else
                cout << "  ";
        }

        // Print the newline character after the end of two
        // nested for loops.
        cout << endl;
    }
    return 0;
}

Output:

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

3) C Implementation

Below is the implementation:

#include <stdio.h>

int main()
{

    // Give the number of rows of the rhombus as static
    // input and store it in a variable.
    int rhombusrows = 8;
    // Loop till the number of rows of the rhombus using For
    // loop.
    for (int m = 0; m < rhombusrows; m++) {
        // Iterate till the first iterator using another For
        // loop(Nested For loop).

        for (int n = 0; n < m; n++) {
            // Print the space character in the inner for
            // loop.

            printf("  ");
        }
        // Loop till the number of rows of the rhombus using
        // For loop(Second Nested For loop).
        for (int r = 0; r < rhombusrows; r++) {
            /*If the parent For loop iterator value is equal
              to 0 or the number of rows-1, then print star
              with a space character. If the current
              iterator's value is equal to 0 or the number
              of rows-1, the print star with a space
              character. Check the above two statements true
              or false using the If condition statement. If
              it is true then print star with a space
              character. Else print space.*/
            if (m == 0 || m == rhombusrows - 1 || r == 0
                || r == rhombusrows - 1)
                printf("* ");
            else
                printf("  ");
        }

        // Print the newline character after the end of two
        // nested for loops.
        printf("\n");
    }
    return 0;
}

Output:

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

Method #2: Using For loop (User Character)

Approach:

  • Give the number of rows of the rhombus as user input and store it in a variable.
  • Give the character to print as user input and store it in a variable.
  • Loop till the number of rows of the rhombus using For loop.
  • Iterate till the first iterator using another For loop(Nested For loop).
  • Print the space character in the inner for loop.
  • Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
  • If the parent For loop iterator value is equal to 0 or the number of rows-1, then print star with a space character.
  • If the current iterator’s value is equal to 0 or the number of rows-1, the print star with a space character.
  • Check the above two statements true or false using the If condition statement.
  • If it is true then print the given character with a space character.
  • Else print space.
  • Print the newline character after the end of two nested for loops.
  • The Exit of the Program.

1) Python Implementation

  • Give the number of rows of the rhombus as user input using int(input()) and store it in a variable.
  • Give the Character as user input using input() and store it in another variable.

Below is the implementation:

# Give the number of rows of the rhombus as user input using int(input()) and store it in a variable.
rhombusrows = int(input(
    'Enter some random number of rows of rhombus = '))
# Give the Character as user input using input() and store it in another variable.
givencharacter = input('Enter some random character = ')
# Loop till the number of rows of the rhombus using For loop.
for m in range(rhombusrows):
  # Iterate till the first iterator using another For loop(Nested For loop).
    for n in range(m):
      # Print the space character in the inner for loop.
        print(' ', end='')
    # Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
    for o in range(rhombusrows):
      # If the parent For loop iterator value is equal to 0 or the number of rows-1, then print star with a space character.
      # If the current iterator's value is equal to 0 or the number of rows-1, the print star with a space character.
      # Check the above two statements true or false using the If condition statement.
      # If it is true then print given character with a space character.
      # Else print space.
        if(m == 0 or m == rhombusrows - 1 or o == 0 or o == rhombusrows - 1):
            print(givencharacter, end=' ')
        else:
            print(' ', end=' ')
    # Print the newline character after the end of two nested for loops.
    print()

Output:

Enter some random number of rows of rhombus = 6
Enter some random character = ~
~ ~ ~ ~ ~ ~ 
  ~               ~ 
    ~               ~ 
      ~               ~ 
        ~               ~ 
          ~ ~ ~ ~ ~ ~

2) C++ Implementation

  • Give the number of rows of the rhombus as user input using cin and store it in a variable.
  • Give the Character as user input using cin and store it in another variable.

Below is the implementation:

#include <iostream>
using namespace std;

int main()
{

    // Give the number of rows of the Right
    // Rhombbus as user input using cin and store it in a
    // variable.
    int rhombusrows;
    char givencharacter;
    cout << "Enter some random number of rows of the "
            "Rhombus = "
         << endl;
    cin >> rhombusrows;
    // Give the Character as user input using cin and store
    // it in another variable.
    cout << "Enter some random character = " << endl;
    cin >> givencharacter;
    cout << endl;
    // Loop till the number of rows of the rhombus using For
    // loop.
    for (int m = 0; m < rhombusrows; m++) {
        // Iterate till the first iterator using another For
        // loop(Nested For loop).

        for (int n = 0; n < m; n++) {
            // Print the space character in the inner for
            // loop.

            cout << "  ";
        }
        // Loop till the number of rows of the rhombus using
        // For loop(Second Nested For loop).
        for (int r = 0; r < rhombusrows; r++) {
            /*If the parent For loop iterator value is equal
              to 0 or the number of rows-1, then print star
              with a space character. If the current
              iterator's value is equal to 0 or the number
              of rows-1, the print star with a space
              character. Check the above two statements true
              or false using the If condition statement. If
              it is true then print given character with a
              space character. Else print space.*/
            if (m == 0 || m == rhombusrows - 1 || r == 0
                || r == rhombusrows - 1)
                cout << givencharacter << " ";
            else
                cout << "  ";
        }

        // Print the newline character after the end of two
        // nested for loops.
        cout << endl;
    }
    return 0;
}

Output:

Enter some random number of rows of rhombus = 6
Enter some random character = ~
~ ~ ~ ~ ~ ~ 
  ~               ~ 
    ~               ~ 
      ~               ~ 
        ~               ~ 
          ~ ~ ~ ~ ~ ~

3) C Implementation

  • Give the number of rows of the Rhombus as user input using scanf and store it in a variable.
  • Give the Character as user input using scanf and store it in another variable.

Below is the implementation:

#include <stdio.h>

int main()
{

    // Give the number of rows of the  Rhombus
    //  as user input using scanf and store it in a
    // variable.
    int rhombusrows;
    char givencharacter;
    // Give the Character as user input using scanf and
    // store it in another variable.
    scanf("%d", &rhombusrows);
    scanf("%c", &givencharacter);
    printf("\n");
    // Loop till the number of rows of the rhombus using For
    // loop.
    for (int m = 0; m < rhombusrows; m++) {
        // Iterate till the first iterator using another For
        // loop(Nested For loop).

        for (int n = 0; n < m; n++) {
            // Print the space character in the inner for
            // loop.

            printf("  ");
        }
        // Loop till the number of rows of the rhombus using
        // For loop(Second Nested For loop).
        for (int r = 0; r < rhombusrows; r++) {
            /*If the parent For loop iterator value is equal
              to 0 or the number of rows-1, then print star
              with a space character. If the current
              iterator's value is equal to 0 or the number
              of rows-1, the print star with a space
              character. Check the above two statements true
              or false using the If condition statement. If
              it is true then print given character with a
              space character. Else print space.*/
            if (m == 0 || m == rhombusrows - 1 || r == 0
                || r == rhombusrows - 1)
                printf("%c ", givencharacter);
            else
                printf("  ");
        }

        // Print the newline character after the end of two
        // nested for loops.
        printf("\n");
    }
    return 0;
}

Output:

6~
~ ~ ~ ~ ~ ~ 
  ~               ~ 
    ~               ~ 
      ~               ~ 
        ~               ~ 
          ~ ~ ~ ~ ~ ~

Related Programs:

Python Program to Print Hollow Mirrored Rhombus Star Pattern Read More »

Python Program to Print Hollow Rhombus Using For Loop Star Pattern

Python Program to Print Hollow Rhombus Star Pattern

Grab the opportunity to learn all effective java programming language concepts from basic to advance levels by practicing these Java Program Examples with Output

Given the number of rows of the rhombus, the task is to print the hollow rhombus Star Pattern in C, C++, and Python.

Examples:

Example1:

Input:

given number of rows of rhombus =11

Output:

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

Example2:

Input:

given number of rows of rhombus =6
given character to print =<

Output:

          < < < < < < 
        <               < 
      <               < 
    <               < 
  <               < 
< < < < < <

Program to Print Hollow Rhombus Star Pattern in C, C++, and Python

Below are the ways to print Hollow Rhombus star patterns in C, C++, and Python.

Method #1: Using For Loop (Star Character)

Approach:

  • Give the number of rows of the rhombus as static input and store it in a variable.
  • Using Nested For loops print the rhombus star pattern.
  • We use the If Else statement to check If the side length of the rhombus(rows) is 0 or maximum – 1.
  • If it is true then print * else print space.
  • The Exit of the Program.

1) Python Implementation

Below is the implementation:

Python Program to Print Hollow Rhombus Star Pattern

# Give the number of rows of the rhombus as static input and store it in a variable.
rhombusrows = 11
# Using Nested For loops print the rhombus star pattern.
for m in range(rhombusrows, 0, -1):
    for n in range(1, m):
        print(' ', end='')
    for k in range(0, rhombusrows):
      # We use the If Else statement to check If the side length of the rhombus(rows) is 0 or maximum – 1.
       # If it is true then print * else print space.
        if(m == 1 or m == rhombusrows or k == 0 or k == rhombusrows - 1):
            print('*', end=' ')
        else:
            print(' ', end=' ')
    print()

Output:

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

2) C++Implementation

Below is the implementation:

CPP Program to Print Hollow Rhombus Using For Loop Star Pattern

#include <iostream>
using namespace std;

int main(void)
{
    // Give the number of rows of the rhombus as static
    // input and store it in a variable.
    int rhombusrows = 6;
    // Using Nested For loops print the rhombus star
    // pattern.
    for (int m = rhombusrows; m > 0; m--) {
        for (int n = 1; n < m; n++) {
            cout << "  ";
        }
        for (int k = 0; k < rhombusrows; k++) {
            // We use the If Else statement to check If the
            // side length of the rhombus(rows) is 0 or
            // maximum – 1. If it is true then print * else
            // print space.
            if (m == 1 || m == rhombusrows || k == 0
                || k == rhombusrows - 1)
            cout << "* ";
            else
                cout << "  ";
        }
        cout << endl;
    }

    return 0;
}

Output:

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

3) C Implementation

Below is the implementation:

C Program to Print Hollow Rhombus Using For Loop Star Pattern

#include <stdio.h>

int main()
{
    // Give the number of rows of the rhombus as static
    // input and store it in a variable.
    int rhombusrows = 9;
    // Using Nested For loops print the rhombus star
    // pattern.
    for (int m = rhombusrows; m > 0; m--) {
        for (int n = 1; n < m; n++) {
            printf("  ");
        }
        for (int k = 0; k < rhombusrows; k++) {
            // We use the If Else statement to check If the
            // side length of the rhombus(rows) is 0 or
            // maximum – 1. If it is true then print * else
            // print space.
            if (m == 1 || m == rhombusrows || k == 0
                || k == rhombusrows - 1)
                printf("* ");
            else
                printf("  ");
        }
        printf("\n");
    }
}

Output:

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

Method #2: Using For Loop (User Character)

Approach:

  • Give the number of rows of the rhombus as static input and store it in a variable.
  • Scan the character to print as user input and store it in a variable.
  • Using Nested For loops print the rhombus star pattern.
  • We use the If Else statement to check If the side length of the rhombus(rows) is 0 or maximum – 1.
  • If it is true then print * else print space.
  • The Exit of the Program.

1) Python Implementation

  • Give the number of sides of the rhombus as user input using int(input()) and store it in a variable.
  • Give the Character as user input using input() and store it in another variable.

Below is the implementation:

D:\Content\Shivam\selenium\Py Images\Python Program to Print Hollow Rhombus Using For Loop User Character.png

# Give the number of sides of the rhombus as user input using int(input()) and store it in a variable.
# Give the Element as user input using int(input()) and store it in another variable.
rhombusrows = int(input('Enter some random number of rows of the rhombus= '))
characte = input('Enter some random character to print = ')
# Using Nested For loops print the rhombus star pattern.
for m in range(rhombusrows, 0, -1):
    for n in range(1, m):
        print(' ', end='')
    for k in range(0, rhombusrows):
      # We use the If Else statement to check If the side length of the rhombus(rows) is 0 or maximum – 1.
       # If it is true then print * else print space.
        if(m == 1 or m == rhombusrows or k == 0 or k == rhombusrows - 1):
            print(characte, end=' ')
        else:
            print(' ', end=' ')
    print()

Output:

Enter some random number of rows of the rhombus= 6
Enter some random character to print = <
          < < < < < < 
        <               < 
      <               < 
    <               < 
  <               < 
< < < < < <

2) C++Implementation

  • Give the number of sides of the rhombus as user input using cin and store it in a variable.
  • Create a character variable.
  • Give the character as user input using cin and store it in another variable.

Below is the implementation:

CPP Program to Print Hollow Rhombus Using For Loop User Character

#include <iostream>
using namespace std;

int main(void)
{
    int rhombusrows;
    char characte;
    // Give the number of rows of the rhombus as user input
    // using cin and
    // store it in a variable.
    cout << "Enter some random number of rows of the "
            "rhombus = "
         << endl;
    cin >> rhombusrows;
    // Create a character variable.
    // Give the character as user input using cin and store
    // it in another variable.
    cout << "Enter some random character to print = "
         << endl;
    cin >> characte;
    cout << endl;
    for (int m = rhombusrows; m > 0; m--) {
        for (int n = 1; n < m; n++) {
            cout << "  ";
        }
        for (int k = 0; k < rhombusrows; k++) {
            // We use the If Else statement to check If the
            // side length of the rhombus(rows) is 0 or
            // maximum – 1. If it is true then print * else
            // print space.
            if (m == 1 || m == rhombusrows || k == 0
                || k == rhombusrows - 1)
                cout << characte << " ";
            else
                cout << "  ";
        }
        cout << endl;
    }

    return 0;
}

Output:

Enter some random number of rows of the rhombus = 
5
Enter some random character to print = 
?
    ? ? ? ? ? 
   ?         ? 
  ?         ? 
 ?         ? 
? ? ? ? ?

3) C Implementation

  • Give the number of sides of the rhombus as user input using scanf and store it in a variable.
  • Create a character variable.
  • Give the character as user input using scanf and store it in another variable.

Below is the implementation:

D:\Content\Shivam\selenium\Py Images\Python Program to Print Hollow Rhombus Using For Loop User Character.png

#include <stdio.h>

int main()
{
    int rhombusrows;
    char characte;
    // Give the number of rows of the rhombus as user input
    // using scanf and
    // store it in a variable.
    // Create a character variable.
    // Give the character as user input using scanf and
    // store it in another variable.
    // Using Nested For loops print the rhombus pattern.
    scanf("%d%c", &rhombusrows, &characte);
    printf("\n");
    // Using Nested For loops print the rhombus star
    // pattern.
    for (int m = rhombusrows; m > 0; m--) {
        for (int n = 1; n < m; n++) {
            printf("  ");
        }
        for (int k = 0; k < rhombusrows; k++) {
            // We use the If Else statement to check If the
            // side length of the rhombus(rows) is 0 or
            // maximum – 1. If it is true then print * else
            // print space.
            if (m == 1 || m == rhombusrows || k == 0
                || k == rhombusrows - 1)
                printf("%c ", characte);
            else
                printf("  ");
        }
        printf("\n");
    }
}

Output:

5 :
    : : : : : 
   :       : 
  :       : 
 :       : 
: : : : :

Related Programs:

Python Program to Print Hollow Rhombus Star Pattern Read More »

Python Program to Print Hollow Square Star Pattern with Diagonals Using For Loop

Python Program to Print Hollow Square Star With Diagonals

Beginners and experienced programmers can rely on these Best Java Programs Examples and code various basic and complex logics in the Java programming language with ease.

Given the sides of the square, the task is to print the hollow Square star pattern with diagonals in C, C++, and Python.

Examples:

Example1:

Input:

given number of sides of square =10

Output:

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

Example2:

Input:

given number of sides of square =10
given character to print =$

Output:

$ $ $ $ $ $ $ $ $ $ 
$ $                   $ $ 
$   $               $   $ 
$       $        $      $ 
$          $   $        $ 
$           $ $         $ 
$           $   $       $ 
$       $          $    $ 
$   $                $  $ 
$ $ $ $ $ $ $ $ $ $

Program to Print Hollow Square Star Pattern with Diagonals in C, C++, and Python

Below are the ways to print the hollow square star with Diagonals pattern in C, C++, and Python.

Method #1: Using For loop (Star Character)

Approach:

  • Give the side of the square as static input and store it in a variable.
  • Loop till the side length of the square using For loop.
  • Loop till the side length of the square using another nested For loop.
  • We use the If Else statement to check If the side length is 0 or maximum – 1. (For the Outer Boundary of the square)
  • We can say it is diagonal if a row equals a column, or a row equals N-i+1 (where i is the current row number).
  • We merge these two conditions using if and or operator.
  • We have or operator in Python,|| operator in C, C++, and Java
  • If it is true then print * else print space.
  • The Exit of the Program.

1)  Python Implementation

Below is the implementation:

Python Program to Print Hollow Square Star Pattern with Diagonals Using For Loop

# Give the side of the square as static input and store it in a variable.
squareside = 10
# Loop till the side length of the square using For loop.
for m in range(squareside):
    # Loop till the side length of the square using another nested For loop.
    for n in range(squareside):
        # We use the If Else statement to check If the side length is 0 or maximum – 1. (For the Outer Boundary of the square)
        # We can say it is diagonal if a row equals a column, or a row equals N-i+1 (where i is the current row number).
        # We merge these two conditions using if and or operator.
        # We have or operator in Python,|| operator in C, C++, and Java
        # If it is true then print * else print space.
        if(m == 0 or m == squareside - 1 or n == 0 or n == squareside - 1 or m == n or n == (squareside - 1 - m)):
            print('*', end=' ')
        else:
            print(' ', end=' ')
    print()

Output:

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

2) C++Implementation

Below is the implementation:

CPP Program to Print Hollow Square Star Pattern with Diagonals Using For Loop

#include <iostream>
using namespace std;

int main()
{

    // Give the side of the square as static input and store
    // it in a variable.
    int squareside = 10;
    // Loop till the side length of the square using For
    // loop.
    for (int m = 0; m < squareside; m++) {
        // Loop till the side length of the square using
        // another nested For loop.
        for (int n = 0; n < squareside; n++) {
            // We use the If Else statement to check If the
            // side length is 0 or maximum – 1.
            if (m == 0 || m == squareside - 1 || n == 0
                || n == squareside - 1)
                cout << "* ";
            else
                cout << "  ";
        }
        cout << endl;
    }

    return 0;
}

Output:

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

3) C Implementation

Below is the implementation:

C Program to Print Hollow Square Star Pattern with Diagonals Using For Loop

#include <stdio.h>

int main()
{
    // Give the side of the square as static input and store
    // it in a variable.
    int squareside = 10;
    // Loop till the side length of the square using For
    // loop.
    for (int m = 0; m < squareside; m++) {
        // Loop till the side length of the square using
        // another nested For loop.
        for (int n = 0; n < squareside; n++) {
            /*We use the If Else statement to check If the
                side length is 0 or maximum – 1. (For the
               Outer Boundary of the square) We can say it
               is diagonal if a row equals a column, or a
               row equals N-i+1 (where i is the current row
                number). We merge these two conditions using
               if and or operator. We have or operator in
               Python,|| operator in C,
                C++, and Java If it is true then print *
               else print space.*/
            if (m == 0 || m == squareside - 1 || n == 0
                || n == squareside - 1 || m == n
                || n == (squareside - 1 - m))
                printf("* ");
            else
                printf("  ");
        }
        printf("\n");
    }
}

Output:

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

Method #2: Using For Loop (User Character)

Approach:

  • Give the side of the square as user input and store it in a variable.
  • Scan the character to print as user input and store it in a variable.
  • Loop till the side length of the square using For loop.
  • Loop till the side length of the square using another nested For loop.
  • We use the If Else statement to check If the side length is 0 or maximum – 1.
  • We can say it is diagonal if a row equals a column, or a row equals N-i+1 (where i is the current row number).
  • We merge these two conditions using if and or operator.
  • We have or operator in Python,|| operator in C, C++, and Java
  • If it is true then print given character else print space.
  • The Exit of the Program.

1) Python Implementation

  • Give the number of sides of the square as user input using int(input()) and store it in a variable.
  • Give the Character as user input using input() and store it in another variable.

Below is the implementation:

Python Program to Print Hollow Square Star Pattern with Diagonals Using For Loop -User Character

# Give the side of the square as user input and store it in a variable.
squareside = int(input('Enter some random number of sides of square = '))
# Scan the character to print as user input and store it in a variable.
characte = input('Enter some random character to print = ')
# Loop till the side length of the square using For loop.
for m in range(squareside):
    # Loop till the side length of the square using another nested For loop.
    for n in range(squareside):
        # We use the If Else statement to check If the side length is 0 or maximum – 1. (For the Outer Boundary of the square)
        # We can say it is diagonal if a row equals a column, or a row equals N-i+1 (where i is the current row number).
        # We merge these two conditions using if and or operator.
        # We have or operator in Python,|| operator in C, C++, and Java
        # If it is true then print * else print space.
        if(m == 0 or m == squareside - 1 or n == 0 or n == squareside - 1 or m == n or n == (squareside - 1 - m)):
            print(characte, end=' ')
        else:
            print(' ', end=' ')
    print()

Output:

Enter some random number of sides of square = 10
Enter some random character to print = $
$ $ $ $ $ $ $ $ $ $ 
$ $                   $ $ 
$   $               $   $ 
$       $        $      $ 
$          $   $        $ 
$           $ $         $ 
$           $   $       $ 
$       $          $    $ 
$   $                $  $ 
$ $ $ $ $ $ $ $ $ $

2) C++Implementation

  • Give the number of sides of the square as user input using cin and store it in a variable.
  • Create a character variable.
  • Give the character as user input using cin and store it in another variable.

Below is the implementation:

CPP Program to Print Hollow Square Star Pattern with Diagonals Using For Loop User Character

#include <iostream>
using namespace std;

int main(void)
{
    int sidesnum;
    char characte;
    // Give the number of sides of the square as user input
    // using cin and
    // store it in a variable.
    cout << "Enter some random number of sides of the "
            "square = "
         << endl;
    cin >> sidesnum;
    // Create a character variable.
    // Give the character as user input using cin and store
    // it in another variable.
    cout << "Enter some random character to print = "
         << endl;
    cin >> characte;
    cout << endl;

    // Using Nested For loops print the square pattern.
    for (int m = 0; m < sidesnum; m++) {
        for (int n = 0; n < sidesnum; n++) {
            /*We use the If Else statement to check If the
             side length is 0 or maximum – 1. (For the
            Outer Boundary of the square) We can say it
            is diagonal if a row equals a column, or a
            row equals N-i+1 (where i is the current row
             number). We merge these two conditions using
            if and or operator. We have or operator in
            Python,|| operator in C,
             C++, and Java If it is true then print *
            else print space.*/
            if (m == 0 || m == sidesnum - 1 || n == 0
                || n == sidesnum - 1 || m == n
                || n == (sidesnum - 1 - m))
                cout << characte << " ";
            else
                cout << "  ";
        }
        cout << endl;
    }

    return 0;
}

Output:

Enter some random number of sides of the square = 
10
Enter some random character to print = 
$
$ $ $ $ $ $ $ $ $ $ 
$ $                   $ $ 
$   $               $   $ 
$       $        $      $ 
$          $   $        $ 
$           $ $         $ 
$           $   $       $ 
$       $          $    $ 
$   $                $  $ 
$ $ $ $ $ $ $ $ $ $

3) C Implementation

  • Give the number of sides of the square as user input using scanf and store it in a variable.
  • Create a character variable.
  • Give the character as user input using scanf and store it in another variable.

Below is the implementation:

C Program to Print Hollow Square Star Pattern with Diagonals Using For Loop User Character

#include <stdio.h>

int main()
{
    int sidesnum;
    char characte;
    // Give the number of sides of the square as user input
    // using scanf and
    // store it in a variable.
    // Create a character variable.
    // Give the character as user input using scanf and
    // store it in another variable.
    // Using Nested For loops print the square pattern.
    scanf("%d%c", &sidesnum, &characte);
    printf("\n");

    for (int m = 0; m < sidesnum; m++) {
        for (int n = 0; n < sidesnum; n++) {
            /*We use the If Else statement to check If the
                side length is 0 or maximum – 1. (For the
               Outer Boundary of the square) We can say it
               is diagonal if a row equals a column, or a
               row equals N-i+1 (where i is the current row
                number). We merge these two conditions using
               if and or operator. We have or operator in
               Python,|| operator in C,
                C++, and Java If it is true then print *
               else print space.*/
            if (m == 0 || m == sidesnum - 1 || n == 0
                || n == sidesnum - 1 || m == n
                || n == (sidesnum - 1 - m))
                printf("%c ", characte);
            else
                printf("  ");
        }
        printf("\n");
    }
}

Output:

10$
$ $ $ $ $ $ $ $ $ $ 
$ $                   $ $ 
$   $               $   $ 
$       $        $      $ 
$          $   $        $ 
$           $ $         $ 
$           $   $       $ 
$       $          $    $ 
$   $                $  $ 
$ $ $ $ $ $ $ $ $ $

Related Programs:

Python Program to Print Hollow Square Star With Diagonals Read More »

Python Program to Print Square Star Pattern

Are you a job seeker and trying to find simple java programs for Interview? This would be the right choice for you, just tap on the link and start preparing the java programs covered to crack the interview.

Given the number of rows and a number, the task is to print a square star pattern in C, C++, and Python.

Examples:

Example1:

Input:

given number of sides of square =13

Output:

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

Example2:

Input:

given number of sides of square =7
given character to print =@

Output:

Enter some random number of sides of the square = 
7
Enter some random character to print = 
@
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @

Program to Print Square Star Pattern in C, C++, and Python

Below are the ways to print square star pattern in C, C++, and Python.

Method #1: Using For Loop (Star Character)

Approach:

  • Give the number of sides of the square as static input and store it in a variable.
  • Using Nested For loops print the square star pattern.
  • The Exit of the Program.

1) Python Implementation

Below is the implementation:

# Give the number of sides of the square as static input and store it in a variable.
squareside = 13
# Using two Nested For loops print the square star pattern.
for m in range(squareside):
    for n in range(squareside):
      # printing the star character
        print('*', end=' ')
    print()

Output:

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

2) C++ Implementation

Below is the implementation:

#include <iostream>
using namespace std;

int main(void)
{
    // Give the number of sides of the square as static
    // input
    // and store it in a variable.
    int squareside = 20;
    // Using Nested For loops print the square pattern.
    for (int m = 1; m <= squareside; m++) {
        for (int n = 1; n <= squareside; n++) {
            // printing the star character
            cout << "* ";
        }
        cout << endl;
    }

    return 0;
}

Output:

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

3) C Implementation

Below is the implementation:

#include <stdio.h>

int main()
{
    // Give the number of sides of the square as static
    // input and store it in a variable.
    int squareside = 5, m, n;
    // Using Nested For loops print the square pattern.
    for (m = 0; m < squareside; m++) {
        for (n = 0; n < squareside; n++) {
            // printing the star character
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

Output:

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

Method #2: Using For Loop (User Character)

Approach:

  • Give the number of sides of the square as user input and store it in a variable.
  • Scan the character to print and store it in a variable.
  • Using Nested For loops.
  • Print the given character
  • The Exit of the Program.

1) Python Implementation

  • Give the number of sides of the square as user input using int(input()) and store it in a variable.
  • Give the Character as user input using input() and store it in another variable.

Below is the implementation:

# Give the number of sides of the square as user input using int(input()) and store it in a variable.
# Give the Element as user input using int(input()) and store it in another variable.
sidesnum = int(input('Enter some random number of sides of the square= '))
characte = input('Enter some random character to print = ')
# Using Nested For loops print the square pattern.
for m in range(sidesnum):
    for n in range(sidesnum):
        print(characte, end=' ')
    print()

Output:

Enter some random number of sides of the square= 13
Enter some random character to print = %
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 
% % % % % % % % % % % % % 

2) C++Implementation

  • Give the number of sides of the square as user input using cin and store it in a variable.
  • Create a character variable.
  • Give the character as user input using cin and store it in another variable.

Below is the implementation:

#include <iostream>
using namespace std;

int main(void)
{
    int sidesnum;
    char characte;
    // Give the number of sides of the square as user input
    // using cin and
    // store it in a variable.
    cout << "Enter some random number of sides of the "
            "square = "
         << endl;
    cin >> sidesnum;
    // Create a character variable.
    // Give the character as user input using cin and store
    // it in another variable.
    cout << "Enter some random character to print = "
         << endl;
    cin >> characte;
    cout << endl;

    // Using Nested For loops print the square pattern.
    for (int m = 1; m <= sidesnum; m++) {
        for (int n = 1; n <= sidesnum; n++) {
            // print the given character
            cout << characte << " ";
        }
        cout << endl;
    }

    return 0;
}

Output:

Enter some random number of sides of the square = 
7
Enter some random character to print = 
@
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 

3) C Implementation

  • Give the number of sides of the square as user input using scanf and store it in a variable.
  • Create a character variable.
  • Give the character as user input using scanf and store it in another variable.

Below is the implementation:

#include <stdio.h>

int main()
{
    int sidesnum;
    char characte;
    // Give the number of sides of the square as user input
    // using scanf and
    // store it in a variable.
     // Create a character variable.
    // Give the character as user input using scanf and
    // store it in another variable.
    // Using Nested For loops print the square pattern.
    scanf("%d%c", &sidesnum,&characte);
    printf("\n");
    
    for (int m = 1; m <= sidesnum; m++) {
        for (int n = 1; n <= sidesnum; n++) {
            // print the given character
            printf("%c ", characte);
        }
        printf("\n");
    }
}

Output:

5$
$ $ $ $ $ 
$ $ $ $ $ 
$ $ $ $ $ 
$ $ $ $ $ 
$ $ $ $ $

Related Programs:

Python Program to Print Square Star Pattern Read More »

Python Program to Print Mirrored Rhombus Star Pattern

Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease.

Given the number of rows of the Rhombus, the task is to print Mirrored Rhombus Star pattern in C, C++, and Python.

Examples:

Example1:

Input:

given number of rows of the rhombus =8

Output:

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

Example2:

Input:

Given number of rows of the rhombus =8
Given character to print ='<'

Output:

<<<<<<<<
 <<<<<<<<
  <<<<<<<<
   <<<<<<<<
    <<<<<<<<
     <<<<<<<<
      <<<<<<<<
       <<<<<<<<

Program to Print Mirrored Rhombus Star Pattern in C, C++, and Python

Below are the ways to print mirrored Rhonbus star Patterns in C, C++, and Python.

Method #1: Using For loop (Star Character)

Approach:

  • Give the number of rows of the rhombus as static input and store it in a variable.
  • Loop till the number of rows of the rhombus using For loop.
  • Iterate till the first iterator using another For loop(Nested For loop).
  • Print the space character in the inner for loop.
  • Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
  • Print the star character in this inner loop with the space character.
  • Print the newline character after the end of two nested for loops.
  • The Exit of the Program.

1) Python Implementation

Below is the implementation:

# Give the number of rows of the rhombus as static input and store it in a variable.
rhombusrows = 8
# Loop till the number of rows of the rhombus using For loop.
for m in range(rhombusrows):
  # Iterate till the first iterator using another For loop(Nested For loop).
    for n in range(m):
      # Print the space character in the inner for loop.
        print(' ', end='')
    # Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
    for o in range(rhombusrows):
      # Print the star character in this inner loop with the space character.
        print('*', end='')
    # Print the newline character after the end of two nested for loops.
    print()

Output:

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

2) C++ Implementation

Below is the implementation:

#include <iostream>
using namespace std;

int main()
{

    // Give the number of rows of the rhombus as static
    // input and store it in a variable.
    int rhombusrows = 8;
    // Loop till the number of rows of the rhombus using For
    // loop.
    for (int m = 0; m < rhombusrows; m++) {
        // Iterate till the first iterator using another For
        // loop(Nested For loop).

        for (int n = 0; n < m; n++) {
            // Print the space character in the inner for
            // loop.

            cout << "  ";
        }
        // Loop till the number of rows of the rhombus using
        // For loop(Second Nested For loop).
        for (int r = 0; r < rhombusrows;
             r++) { // Print the star character in this
                    // inner loop with the space character.
            cout << "* ";
        }

        // Print the newline character after the end of two
        // nested for loops.
        cout << endl;
    }
    return 0;
}

Output:

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

3) C Implementation

Below is the implementation:

#include <stdio.h>

int main()
{

    // Give the number of rows of the rhombus as static
    // input and store it in a variable.
    int rhombusrows = 8;
    // Loop till the number of rows of the rhombus using For
    // loop.
    for (int m = 0; m < rhombusrows; m++) {
        // Iterate till the first iterator using another For
        // loop(Nested For loop).

        for (int n = 0; n < m; n++) {
            // Print the space character in the inner for
            // loop.

            printf("  ");
        }
        // Loop till the number of rows of the rhombus using
        // For loop(Second Nested For loop).
        for (int r = 0; r < rhombusrows;
             r++) { // Print the star character in this
                    // inner loop with the space character.
            printf("* ");
        }

        // Print the newline character after the end of two
        // nested for loops.
        printf("\n");
    }
    return 0;
}

Output:

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

Method #2: Using For loop (User Character)

Approach:

  • Give the number of rows of the rhombus as user input and store it in a variable.
  • Give the character to print as user input and store it in a variable.
  • Loop till the number of rows of the rhombus using For loop.
  • Iterate till the first iterator using another For loop(Nested For loop).
  • Print the space character in the inner for loop.
  • Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
  • Print the given character in this inner loop with the space character.
  • Print the newline character after the end of two nested for loops.
  • The Exit of the Program.

1) Python Implementation

  • Give the number of rows of the rhombus as user input using int(input()) and store it in a variable.
  • Give the Character as user input using input() and store it in another variable.

Below is the implementation:

# Give the number of rows of the rhombus as user input using int(input()) and store it in a variable.
rhombusrows = int(input(
    'Enter some random number of rows of rhombus = '))
# Give the Character as user input using input() and store it in another variable.
givencharacter = input('Enter some random character = ')
# Loop till the number of rows of the rhombus using For loop.
for m in range(rhombusrows):
  # Iterate till the first iterator using another For loop(Nested For loop).
    for n in range(m):
      # Print the space character in the inner for loop.
        print(' ', end='')
    # Loop till the number of rows of the rhombus using For loop(Second Nested For loop).
    for o in range(rhombusrows):
      # Print the givencharacter in this inner loop with the space character.
        print(givencharacter, end='')
    # Print the newline character after the end of two nested for loops.
    print()

Output:

Enter some random number of rows of rhombus = 8
Enter some random character = <
<<<<<<<<
 <<<<<<<<
  <<<<<<<<
   <<<<<<<<
    <<<<<<<<
     <<<<<<<<
      <<<<<<<<
       <<<<<<<<

2) C++ Implementation

  • Give the number of rows of the rhombus as user input using cin and store it in a variable.
  • Give the Character as user input using cin and store it in another variable.

Below is the implementation:

#include <iostream>
using namespace std;

int main()
{

    // Give the number of rows of the Right
    // Rhombbus as user input using cin and store it in a
    // variable.
    int rhombusrows;
    char givencharacter;
    cout << "Enter some random number of rows of the "
            "Rhombus = "
         << endl;
    cin >> rhombusrows;
    // Give the Character as user input using cin and store
    // it in another variable.
    cout << "Enter some random character = " << endl;
    cin >> givencharacter;
    cout << endl;
    // Loop till the number of rows of the rhombus using For
    // loop.
    for (int m = 0; m < rhombusrows; m++) {
        // Iterate till the first iterator using another For
        // loop(Nested For loop).

        for (int n = 0; n < m; n++) {
            // Print the space character in the inner for
            // loop.

            cout << "  ";
        }
        // Loop till the number of rows of the rhombus using
        // For loop(Second Nested For loop).
        for (int r = 0; r < rhombusrows;
             r++) { // Print the givencharacter in this
                    // inner loop with the space character.
            cout << givencharacter<<" ";
        }

        // Print the newline character after the end of two
        // nested for loops.
        cout << endl;
    }
    return 0;
}

Output:

Enter some random number of rows of rhombus = 
8
Enter some random character = 
<
<<<<<<<<
 <<<<<<<<
  <<<<<<<<
   <<<<<<<<
    <<<<<<<<
     <<<<<<<<
      <<<<<<<<
       <<<<<<<<

3) C Implementation

  • Give the number of rows of the Rhombus as user input using scanf and store it in a variable.
  • Give the Character as user input using scanf and store it in another variable.

Below is the implementation:

#include <stdio.h>

int main()
{

    // Give the number of rows of the  Rhombus
    //  as user input using scanf and store it in a
    // variable.
    int rhombusrows;
    char givencharacter;
    // Give the Character as user input using scanf and
    // store it in another variable.
    scanf("%d", &rhombusrows);
    scanf("%c", &givencharacter);
    printf("\n");
    // Loop till the number of rows of the rhombus using For
    // loop.
    for (int m = 0; m < rhombusrows; m++) {
        // Iterate till the first iterator using another For
        // loop(Nested For loop).

        for (int n = 0; n < m; n++) {
            // Print the space character in the inner for
            // loop.

            printf("  ");
        }
        // Loop till the number of rows of the rhombus using
        // For loop(Second Nested For loop).
        for (int r = 0; r < rhombusrows;
             r++) { // Print the givencharacter in this
                    // inner loop with the space character.
            printf("%c ", givencharacter);
        }

        // Print the newline character after the end of two
        // nested for loops.
        printf("\n");
    }
    return 0;
}

Output:

8<
<<<<<<<<
 <<<<<<<<
  <<<<<<<<
   <<<<<<<<
    <<<<<<<<
     <<<<<<<<
      <<<<<<<<
       <<<<<<<<

Related Programs:

Python Program to Print Mirrored Rhombus Star Pattern Read More »

Python Program to Print Double the Number Pattern

The best and excellent way to learn a java programming language is by practicing Simple Java Program Examples as it includes basic to advanced levels of concepts.

Given the number of rows, the task is to print Double the Number Pattern in C, C++, and Python.

Examples:

Example1:

Input:

Given number of rows = 10

Output:

1 
2 1 
4 2 1 
8 4 2 1 
16 8 4 2 1 
32 16 8 4 2 1 
64 32 16 8 4 2 1 
128 64 32 16 8 4 2 1 
256 128 64 32 16 8 4 2 1

Example2:

Input:

Given number of rows = 7

Output:

  1 
  2   1 
  4   2   1 
  8   4   2   1 
 16   8   4   2   1 
 32  16   8   4   2   1

Program to Print Double the Number Pattern in C, C++, and Python

Below are the ways to print Double the Number Pattern in C, C++, and Python.

Method #1: Using For Loop (Static Input)

Approach:

  • Give the number of rows as static input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from iterator value of the parent For loop -1 to 0 in decreasing order using another for loop(Nested For loop).
  • Print the 2 power n value with space where n is the value of the inner for loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

1) Python Implementation

Below is the implementation:

# Give the number of rows as static input and store it in a variable.
numbrrows = 7
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbrrows):
    # Loop from iterator value of the parent For loop -1 to 0
    # in decreasing order using another for loop(Nested For loop).
    for n in range(m - 1, -1, -1):
        # Print the 2 power n value with space where n is the value of the inner for loop.
        print(2**n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

  1 
  2   1 
  4   2   1 
  8   4   2   1 
 16   8   4   2   1 
 32  16   8   4   2   1

2) C++ Implementation

Below is the implementation:

#include <iostream>
#include <math.h>
using namespace std;

int main()
{

    // Give the number of rows as static input and store it
    // in a variable.
    int numbrrows = 10;
    // Loop from 1 to the number of rows using For loop.
    for (int m = 1; m < numbrrows; m++) {
        /*  Loop from iterator value of the parent For loop
     -1 to 0 in decreasing order using another for
     loop(Nested For loop)*/
        for (int n = m - 1; n >= 0; n--) {
            // Print the 2 power n value with space where n
            // is the value of the inner for loop.
            cout << pow(2, n) << " ";
        }
        // Print the Newline character after the end of the
        // inner loop.
        cout << endl;
    }
    return 0;
}

Output:

1 
2 1 
4 2 1 
8 4 2 1 
16 8 4 2 1 
32 16 8 4 2 1 
64 32 16 8 4 2 1 
128 64 32 16 8 4 2 1 
256 128 64 32 16 8 4 2 1

3) C Implementation

Below is the implementation:

#include <math.h>
#include <stdio.h>
int main()
{

    // Give the number of rows as static input and store it
    // in a variable.
    int numbrrows = 4;
    // Loop from 1 to the number of rows using For loop.
    for (int m = 1; m < numbrrows; m++) {
        /*  Loop from iterator value of the parent For loop
     -1 to 0 in decreasing order using another for
     loop(Nested For loop)*/
        for (int n = m - 1; n >= 0; n--) {
            // Print the 2 power n value with space where n
            // is the value of the inner for loop.
            int powervalu = pow(2, n);
            printf("%d ", powervalu);
        }
        // Print the Newline character after the end of the
        // inner loop.
        printf("\n");
    }
    return 0;
}

Output:

1 
2 1 
4 2 1

Method #2: Using For Loop (User Input)

Approach:

  • Give the number of rows as user input and store it in a variable.
  • Loop from 1 to the number of rows using For loop.
  • Loop from iterator value of the parent For loop -1 to 0 in decreasing order using another for loop(Nested For loop).
  • Print the 2 power n value with space where n is the value of the inner for loop.
  • Print the Newline character after the end of the inner loop.
  • The Exit of the Program.

1) Python Implementation

Give the number of rows as user input using int(input()) and store it in a variable.

Below is the implementation:

# Give the number of rows as user input using int(input()) and store it in a variable.
numbrrows = int(input('Enter some random number of rows = '))
# Loop from 1 to the number of rows using For loop.
for m in range(1, numbrrows):
    # Loop from iterator value of the parent For loop -1 to 0
    # in decreasing order using another for loop(Nested For loop).
    for n in range(m - 1, -1, -1):
        # Print the 2 power n value with space where n is the value of the inner for loop.
        print(2**n, end=' ')
    # Print the Newline character after the end of the inner loop.
    print()

Output:

Enter some random number of rows = 8
1 
2 1 
4 2 1 
8 4 2 1 
16 8 4 2 1 
32 16 8 4 2 1 
64 32 16 8 4 2 1

2) C++ Implementation

Give the number of rows as user input using cin and store it in a variable.

Below is the implementation:

#include <iostream>
#include <math.h>
using namespace std;
int main()
{

    // Give the number of rows as user input using
    // int(input()) and store it in a variable.
    int numbrrows;
    cin >> numbrrows;
    // Loop from 1 to the number of rows using For loop.
    for (int m = 1; m < numbrrows; m++) {
        /*  Loop from iterator value of the parent For loop
     -1 to 0 in decreasing order using another for
     loop(Nested For loop)*/
        for (int n = m - 1; n >= 0; n--) {
            // Print the 2 power n value with space where n
            // is the value of the inner for loop.
            cout << pow(2, n) << " ";
        }
        // Print the Newline character after the end of the
        // inner loop.
        cout << endl;
    }

    return 0;
}

Output:

5
1 
2 1 
4 2 1 
8 4 2 1

3) C Implementation

Give the number of rows as user input using scanf and store it in a variable.

Below is the implementation:

#include <math.h>
#include <stdio.h>
int main()
{

    // Give the number of rows as user input using scanf and
    // store it in a variable.
    int numbrrows;
    scanf("%d", &numbrrows);
    // Loop from 1 to the number of rows using For loop.
    for (int m = 1; m < numbrrows; m++) {
        /*  Loop from iterator value of the parent For loop
     -1 to 0 in decreasing order using another for
     loop(Nested For loop)*/
        for (int n = m - 1; n >= 0; n--) {
            // Print the 2 power n value with space where n
            // is the value of the inner for loop.
            int powervalu = pow(2, n);
            printf("%d ", powervalu);
        }
        // Print the Newline character after the end of the
        // inner loop.
        printf("\n");
    }
    return 0;
}

Output:

5
1 
2 1 
4 2 1 
8 4 2 1

Related Programs:

Python Program to Print Double the Number Pattern Read More »

Program to Print Square Number Pattern in C,C++ and Python

Python Program to Print Square Number Pattern

Enhancing programming skills is very important no matter what language you have chosen. So, practice frequently with these simple java programs examples and excel in coding the complex logic.

Given the number of rows and a number, the task is to print a square number pattern in C, C++, and Python.

Examples:

Example1:

Input:

given number of sides = 5
given element of square =3

Output:

3 3 3 3 3 
3 3 3 3 3 
3 3 3 3 3 
3 3 3 3 3 
3 3 3 3 3

Example2:

Input:

given number of sides = 7
given element of square =9

Output:

9 9 9 9 9 9 9 
9 9 9 9 9 9 9 
9 9 9 9 9 9 9 
9 9 9 9 9 9 9 
9 9 9 9 9 9 9 
9 9 9 9 9 9 9 
9 9 9 9 9 9 9

Program to Print Square Number Pattern in C, C++, and Python

Below are the ways to print square number pattern in C, C++, and Python.

Method #1: Using For loop (Element is of static input)

Approach:

  • Give the number of sides of the square as static input and store it in a variable.
  • Using Nested For loops print the square pattern.
  • The Exit of the Program.

1) Python Implementation

Below is the implementation:

# Give the number of sides of the square as static input and store it in a variable.
sidesnum = 10
# Using Nested For loops print the square pattern.
for m in range(sidesnum):
    for n in range(sidesnum):
        print('1', end=' ')
    print()

Output:

1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1 1 1

2) C++ Implementation

Below is the implementation:

#include <iostream>
using namespace std;

int main(void)
{
    // Give the number of sides of the square as static
    // input
    // and store it in a variable.
    int sidesnum = 7;
    // Using Nested For loops print the square pattern.
    for (int m = 1; m <= sidesnum; m++) {
        for (int n = 1; n <= sidesnum; n++) {
            cout << "1 ";
        }
        cout << endl;
    }

    return 0;
}

Output:

1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1

3) C Implementation

Below is the implementation:

#include<stdio.h>
 
int main()
{
    // Give the number of sides of the square as static input
    // and store it in a variable.
    int sidesnum = 7, m, n;
   // Using Nested For loops print the square pattern.
    for(m = 0; m < sidesnum; m++)
    {
    	for(n = 0; n < sidesnum; n++)
        {
           	printf("1 ");
        }
        printf("\n");
    }
    return 0;
}

Output:

1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 
1 1 1 1 1 1 1 

Method #2: Using For loop (Element is of User input)

Approach:

  • Give the number of sides of the square as user input and store it in a variable.
  • Give the Element as user input and store it in another variable.
  • Using Nested For loops print the square pattern.
  • The Exit of the Program.

1) Python Implementation

  • Give the number of sides of the square as user input using int(input()) and store it in a variable.
  • Give the Element as user input using int(input()) and store it in another variable.

Below is the implementation:

# Give the number of sides of the square as user input using int(input()) and store it in a variable.
# Give the Element as user input using int(input()) and store it in another variable.
sidesnum = int(input('Enter some random number of sides = '))
eleme = int(input('Enter some random element = '))
# Using Nested For loops print the square pattern.
for m in range(sidesnum):
    for n in range(sidesnum):
        print(eleme, end=' ')
    print()

Output:

Enter some random number of sides = 11
Enter some random element = 23
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23 
23 23 23 23 23 23 23 23 23 23 23

2) C++Implementation

  • Give the number of sides of the square as user input using cin and store it in a variable.
  • Give the Element as user input using cin and store it in another variable.

Below is the implementation:

#include <iostream>
using namespace std;

int main(void)
{
    int sidesnum, eleme;
    // Give the number of sides of the square as user input
    // using cin and
    // store it in a variable.
    cin >> sidesnum;
    // Give the Element as user input using cin and store it
    // in another variable.
    cin >> eleme;

    // Using Nested For loops print the square pattern.
    for (int m = 1; m <= sidesnum; m++) {
        for (int n = 1; n <= sidesnum; n++) {
            cout << eleme << " ";
        }
        cout << endl;
    }

    return 0;
}

3) C Implementation

  • Give the number of sides of the square as user input using scanf and store it in a variable.
  • Give the Element as user input using scanf and store it in another variable.

Below is the implementation:

#include<stdio.h>
 
int main()
{  int sidesnum, eleme;
    // Give the number of sides of the square as user input
    // using cin and
    // store it in a variable.
    scanf("%d",&sidesnum);
    // Give the Element as user input using cin and store it
    // in another variable.
   scanf("%d",&eleme);
    // Using Nested For loops print the square pattern.
    for (int m = 1; m <= sidesnum; m++) {
        for (int n = 1; n <= sidesnum; n++) {
            printf("%d ",eleme);
        }
        printf("\n");
    }

}

Output:

22
5
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5

Related Programs:

Python Program to Print Square Number Pattern Read More »