TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Program To Print Pattern 7

Program To Print Pattern 7 on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph, pattern, string etc.

<< Back to PROGRAM

Write a program to print the following pattern on the console.

12344321

123**321

12****21

1******1

Algorithm

  • STEP 1: START
  • STEP 2: SET lines=15
  • STEP 3: Initialize i,j,k,and l
  • STEP 4: SET space=0
  • STEP 5: SET i=1
  • STEP 6: REPEAT STEP 7 TO 20 UNTIL i is less than lines
  • STEP 7: SET j=1
  • STEP 8: REPEAT STEP 9 UNTIL j is less than or equals to space.
  • STEP 9: PRINT " " and SET J=J+1
  • STEP 10: SET j=1
  • STEP 11: REPEAT STEP 12 and 13 UNTIL j is less than or equals to lines
  • STEP 12: IF j is less than equals lines-i PRINT j ELSE PRINT *
  • STEP 13: SET j=j+1
  • STEP 14: DECREMENT j by 1
  • STEP 15: REPEAT STEP 16 and 17 UNTIL j is greater than 0
  • STEP 16: IF j is greater than lines-i PRINT * ELSE PRINT j
  • STEP 17: SET j=j-1
  • STEP 18: IF lines-i is greater than 9 INCREMENT space by 1
  • STEP 19: PRINT new line
  • STEP 20: SET i=i+1
  • STEP 21: EXIT

Solution:

C Program:

#include <stdio.h>
int main()
{
    int lines=15;
    int i,j,k,l;
    int space=0; 
    for(i=1;i<=lines;i++){// this loop is use to print lines
        for(j=1;j<=space;j++){// this loop is used to print the space
            printf(" ");
        }
        for(j=1;j<=lines;j++){// this loop is used to print numbers in a line
            if(j<=(lines-i))
            printf("%d",j);
            else
            printf("*");
        }
        j--;
        while(j>0){// this loop is used to print numbers in a line
            if(j>lines-i)
            printf("*");
            else
            printf("%d",j);
            j--;
        }
        if((lines-i)>9)
        space=space+1;
    printf("\n");
    }
}

Output:

program to print the pattern 7

PHP Program:

<?php
$lines=15;
$i;
$j;
$k;
$l;
    $space=0;
    for($i=0;$i<$lines;$i++){// this loop is used to print lines
         for($j=1;$j<=$space;$j++){//this loop is used to print space in a line
            echo " ";
        }
           for($j=1;$j<=$lines;$j++){// this loop is used to print numbers 
            if($j<=($lines-$i))
            echo $j;
            else
            echo "*";
        }
       $j--;
        while($j>0){//this loop is used to print numbers in a line
            if($j>$lines-$i)
            echo "*";
            else
            echo $j;
            $j--;
        }
        if(($lines-$i)>9)// this loop is used to increment space 
        $space=$space+1;
    echo "<br>";
    }
?>

Output:

program to print the pattern 7

Java Program:

public class Main
{
	public static void main(String[] args) {
    int lines=15;
    int i,j,k,l;
    int space=0;  
    for(i=0;i<lines;i++){// this loop is used to print lines
        for(j=1;j<=space;j++){// this loop is used to print space in a line
            System.out.print(" ");
        }
        for(j=1;j<=lines;j++){// this loop is used to print numbers in a line
            if(j<=(lines-i))
            System.out.print(j);
            else
            System.out.print("*");
        }
        j--;
        while(j>0){// this loop is used to print numbers in a line
            if(j>lines-i)
            System.out.print("*");
            else
            System.out.print(j);
            j--;
        }
        if((lines-i)>9)// this loop is used to increment space
        space=space+1;
    System.out.println("");
    }
}
}

Output:

program to print the pattern 7

C# Program:

using System.IO;
using System;
public class Program
{
   public static void Main(String[] args)
    {
    int lines=15;
    int i,j,k,l;
    int space=0;
    for(i=0;i<lines;i++){// this loop is used to print the lines
        for(j=1;j<=space;j++){// this loop is used to print space in a line
            Console.Write(" ");
        }
        
        for(j=1;j<=lines;j++){// this loop is used to print numbers in a line
            if(j<=(lines-i))
            Console.Write(j);
            else
            Console.Write("*");
        }
        j--;
        while(j>0){// this loop is used to print numbers in a line
            if(j>lines-i)
            Console.Write("*");
            else
            Console.Write(j);
            j--;
        }
        if((lines-i)>9)// this loop is used to increment space
        space=space+1;
    Console.WriteLine("");
    }
    }
}

Output:

program to print the pattern 7

Python Program:

lines=15
i=1
j=1
k=1
l=1
space=0;
while i<lines: #this loop is used to print the lines
    j=1
    while j<=space:#this loop is used to print space in a line
        print(' ', end='', flush=True)
        j=j+1
    j=1
    while j<=lines:# this loop is used to print numbers in a line
        if j<=lines-i:
            print(j, end='', flush=True)
        else:
            print('*', end='', flush=True)
        j=j+1
    j=j-1
    while j>0:# this loop is used to print numbers in a line
        if j>lines-i:
            print('*', end='', flush=True)
        else:
            print(j, end='', flush=True)
        j=j-1
    if lines-i>9:# this loop is used to increment space
        space=space+1
    print("")
    i=i+1

Output:

program to print the pattern 7




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf