You can mail me Contact Me!

Program to construct the stars (*) pattern, using a nested for loop

Program to construct the stars (*) pattern, using a nested for loop

Square Pattern

  • Algorithm for Square Pattern:
    1. Display the title "Square Pattern"
    2. Set the size of the square (e.g., 5)
    3. Use nested loops:
      • Outer loop runs for the number of rows (i.e., size)
      • Inner loop runs for the number of columns (i.e., size)
      • Print the "*" character in each iteration of the inner loop, with a space after it
    4. After each row, move to a new line by printing an empty line

  • Hello, dear reader! 👋

    Thanks for visiting my blog! I’m a student just like you, sharing what I learn to help others with Python programming. I hope my posts are useful for your studies! 😊

    If you find this post helpful, please leave a comment—even just a few emojis will make my day! 🐍✨ Your feedback keeps me motivated to create more content for everyone. 🚀

    Happy programming!
    Abhin Krishna, S01, EB Department, MEC


    Pseudocode for Square Pattern:
    
    START
    DISPLAY "Square Pattern"
    SET size = 5
    FOR i FROM 0 TO size - 1
        FOR j FROM 0 TO size - 1
            PRINT "*" FOLLOWED BY A SPACE
        PRINT NEW LINE
    PRINT NEW LINE
    END
    
    Program for Square Pattern:
    
    print("Square Pattern:")
    size = 5
    for i in range(size):
        for j in range(size):
            print('*', end=' ')
        print()
    
    print()  # Add an empty line for separation
    
    Flowchart for Square Pattern:
    flowchart TD A([Start]) --> B[/Display "Square Pattern"/] B --> C[Set size = 5] C --> D[i = 0] D --> E[j = 0] E --> F[/Print "*" with space/] F --> G[j = j + 1] G --> H{j < size?} H -- Yes --> E H -- No --> I[/Print new line/] I --> J[i = i + 1] J --> K{i < size?} K -- Yes --> D K -- No --> L[/Print new line/] L --> M([End])

    Important!
    If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.

    Right-Angled Triangle Pattern

    Algorithm for Right-Angled Triangle Pattern:
    1. Display the title "Right-Angled Triangle Pattern"
    2. Set the size of the triangle (e.g., 5)
    3. Use nested loops:
      • Outer loop runs for the number of rows (i.e., size)
      • Inner loop runs for the number of columns (i.e., current row number)
      • Print the "*" character in each iteration of the inner loop, with a space after it
    4. After each row, move to a new line by printing an empty line
    Pseudocode for Right-Angled Triangle Pattern:
    
    START
    DISPLAY "Right-Angled Triangle Pattern"
    SET size = 5
    FOR i FROM 1 TO size
        FOR j FROM 1 TO i
            PRINT "*" FOLLOWED BY A SPACE
        PRINT NEW LINE
    PRINT NEW LINE
    END
    
    Program for Right-Angled Triangle Pattern:
    
    print("Right-Angled Triangle Pattern:")
    size = 5
    for i in range(1, size + 1):
        for j in range(i):
            print('*', end=' ')
        print()
    
    print()  # Add an empty line for separation
    
    Flowchart for Right-Angled Triangle Pattern:
    flowchart TD A([Start]) --> B[/Display "Right-Angled Triangle Pattern"/] B --> C[Set size = 5] C --> D[i = 1] D --> E[j = 1] E --> F[/Print "*" with space/] F --> G[j = j + 1] G --> H{j <= i?} H -- Yes --> E H -- No --> I[/Print new line/] I --> J[i = i + 1] J --> K{i <= size?} K -- Yes --> D K -- No --> L[/Print new line/] L --> M([End])

    Important!
    If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.

    Pyramid Pattern

    Algorithm for Pyramid Pattern:
    1. Display the title "Pyramid Pattern"
    2. Set the size of the pyramid (e.g., 5)
    3. Use nested loops:
      • Outer loop runs for the number of rows (i.e., size)
      • First inner loop runs for the number of leading spaces (i.e., size - current row number - 1)
      • Second inner loop runs for the number of stars (i.e., 2 * current row number + 1)
      • Print the leading spaces, then print the stars with a space after each
    4. After each row, move to a new line by printing an empty line
    Pseudocode for Pyramid Pattern:
    
    START
    DISPLAY "Pyramid Pattern"
    SET size = 5
    FOR i FROM 0 TO size - 1
        FOR j FROM 0 TO size - i - 1
            PRINT " " FOLLOWED BY A SPACE
        FOR k FROM 0 TO 2 * i
            PRINT "*" FOLLOWED BY A SPACE
        PRINT NEW LINE
    PRINT NEW LINE
    END
    
    Program for Pyramid Pattern:
    
    print("Pyramid Pattern:")
    size = 5
    for i in range(size):
        # Print leading spaces
        for j in range(size - i - 1):
            print(' ', end=' ')
        # Print stars
        for k in range(2 * i + 1):
            print('*', end=' ')
        print()
    
    print()  # Add an empty line for separation
    
    Flowchart for Pyramid Pattern:
    flowchart TD A([Start]) --> B[/Display "Pyramid Pattern"/] B --> C[Set size = 5] C --> D[i = 0] D --> E[j = 0] E --> F[/Print " " with space/] F --> G[j = j + 1] G --> H{j < size - i - 1?} H -- Yes --> E H -- No --> I[k = 0] I --> J[/Print "*" with space/] J --> K[k = k + 1] K --> L{k <= 2 * i?} L -- Yes --> J L -- No --> M[/Print new line/] M --> N[i = i + 1] N --> O{i < size?} O -- Yes --> D O -- No --> P[/Print new line/] P --> Q([End])

    Important!
    If you find any mistakes in my code or flowchart, please comment below this post. I will be happy to correct them and clear up any doubts you may have.




    Post a Comment

    Cookie Consent
    We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
    Oops!
    It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
    Site is Blocked
    Sorry! This site is not available in your country.