Q:

Write a program to print the following pattern

belongs to collection: Pattern Programs

0

5432*

543*1

54*21

5*321

*4321

Algorithm

  • STEP 1: START
  • STEP 2: SET lines=5
    SET i=1
  • Step 3: REPEAT STEP 4 TO 8 UNTIL i is less than or equals to lines
  • STEP 4: SET j=lines
  • STEP 5: REPEAT STEP 6 and 7 UNTIL j is greater than 0
  • STEP 6: IF j!=i
    PRINT j
    ELSE
    PRINT *
  • STEP 7: j=j-1
  • STEP 8: i=i+1
  • Step 9: EXIT

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C Program:

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

 

Output:

5432*

543*1

54*21

5*321

*4321

 

Java Program:

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

 

Output:

5432*
543*1
54*21
5*321
*4321

 

C# Program:

using System;                     
public class Program  
{  
    public static void Main()  
    {  
         int i,j,lines=5;  
    for(i=1;i<=lines;i++){// this loop is used to print the lines  
       for(j=lines;j>=1;j--){// this loop is used to print numbers in a line  
           if(j!=i)  
            Console.Write(j);  
            else  
             Console.Write("*");  
    }   
    Console.WriteLine("\n");  
    }  
      
    }  
}  

 

Output:

5432*

543*1

54*21

5*321

*4321

 

PHP Program:

<?php  
  $i;  
  $j;  
  $lines=5;  
  
  for($i=1;$i<=$lines;$i++){// this loop is used to print lines   
       for($j=$lines;$j>=1;$j--){// this loop used print numbers in a line  
           if($j!=$i)  
            echo $j;  
            else  
             echo '*';  
    }   
    echo "<br>" ;          
    }  
?>  

 

Output:

 5432*
543*1
54*21
5*321
*4321

 

Python Program:

lines=5  
i=1  
while(i<=lines):# this loop is used to print lines  
    j=lines  
    while (j>=1):# this loop is used to print numbers in a line  
        if j!=i:  
            print(j, end='', flush=True)  
        else:  
            print('*', end='', flush=True)  
        j=j-1  
    print("")  
    i=i+1;  

 

Output:

 5432*

543*1

54*21

5*321

*4321

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a program to print the following pattern... >>
<< Write a program to print the following pattern...