Home » Program To Print Pattern 5

Program To Print Pattern 5

by Online Tutorials Library

Write a program to print the following pattern

program to print the pattern 5

Algorithm

  • STEP 1: START
  • STEP 2: SET lines=8, i=1,j=1,k=1
  • STEP 3: REPEAT STEP 4 to 13 UNTIL i is less than lines
  • STEP 4: SET j=1
  • STEP 5: REPEAT STEP 6 and 7 UNTIL j is less than or equals to (lines/2)
  • STEP 6: IF j is equals to i PRINT j
    ELSE IF i is greater than 4 and j equals lines-i PRINT j
    ELSE PRINT ” “
  • STEP 7: j = j + 1
  • STEP 8: j = j – 2
  • STEP 9: REPEAT STEP 10 and 11 UNTIL j is greater than 0
  • STEP 10: IF j is equals to i PRINT j
    ELSE IF i is greater than 4 and j equals lines-i PRINT j
    ELSE PRINT ” “
  • STEP 11: j = j – 1
  • STEP 12: PRINT a new line
  • STEP 13: i = i + 1
  • STEP 14: EXIT

Solution:

C Program:

Output:

program to print the pattern 5

Java Program:

Output:

program to print the pattern 5

C# Program:

Output:

program to print the pattern 5

PHP Program:

Output:

program to print the pattern 5

Python Program:

Output:

program to print the pattern 5

You may also like