Q:

Program to print the following pattern

belongs to collection: Pattern Programs

0

Algorithm

  1. Start
  2. Let i be an integer number.
  3. Let j be an integer number.
  4. Let n be a integer number and initialize by 1.
  5. Repeat step 6 to 9 until all value parsed.
  6. Set i = 0 and check i<6;
  7. Set j = 1 and check j <= i;
  8. Print number n.
  9. Then n++;
  10. End

In this program, we are creating a right-angled triangle of numbers in increasing order. We are creating two loops, and 2nd loop is executing according to the first loop, inside 2nd loop printing the number row-wise i loop times.

1
2 3
4 5 6
7 8 9 10

All Answers

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

JAVA

package programs;  
public class pattern13   
{  
    public static void main(String[] args)   
    {  
        int n=1;  
        for(int i=0;i<6;i++)  
        {  
             for(int j=1;j<i;j++)  
             {  
                 System.out.print(" "+n);  
               n++;  
             }  
             System.out.println("");  
        }  
    }  
}  

 

Python

n = 5  
k=1  
for i in range(1,n):  
    for j in range(0,i):  
        print(k),  
        k=k+1  
    print("")  

 

C program

#include <stdio.h>  
int main()  
{  
 int size = 5,n=1;  
   for (int i = size; i != 0; i--)   
        {  
            for (int j = 0; j<size-i; j++)  
            {  
                printf("%d",n);  
                n++;  
            }  
                printf("\n");      
        }  
    return 0;  
}   

 

 

C# program

using System;  
public class Program  
{  
    public static void Main(string[] args)  
    {  
        int i, j, rows, k = 1;   
        Console.Write("\n\n");  
        rows = 4;  
        for (i = 1; i <= rows; i++)  
        {  
            for (j = 1; j <= i; j++)  
                Console.Write("{0} ", k++);  
            Console.Write("\n");  
        }    
    }  
}    

 

PHP program

<?php  
$rows = 5;  
$n = 1;  
for($i = $rows; $i != 0; $i--)  
{  
    for($space = 0; $space < $rows - $i; ++$space)  
    {  
        echo $n;  
          $n++;  
    }  
  echo "<br>";  
}  
?>  

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

total answers (1)

Program to print the following pattern... >>
<< Program to print the following pattern...