C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Program to print the following patternAlgorithm
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 JAVApackage 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(""); } } } Pythonn = 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# programusing 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>"; } ?>
Next TopicProgram to Print pattern 18
|