C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Program to print the following pattern
1 Algorithm
JAVA
public class Pattern4
{
public static void main(String[] args)
{
int n = 5;
for(int i = 0 ; i <= n ; i++)
{
for(int j = 0 ; j < i ; j++)
{
System.out.print(j+1);
}
System.out.println("");
}
}
}
Python
lastNumber = 6
for row in range(1, lastNumber):
for column in range(1, row + 1):
print(column),
print("")
C program
#include <stdio.h>
int main()
{
int i,j,n;
n = 8;
for(i=1;i<6;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}
C# program
using System;
public class Program
{
public static void Main(string[] args)
{
for (int row = 1; row <= 5; ++row)
{
for (int col = 1; col <= row; ++col)
{
Console.Write(col);
}
Console.WriteLine();
}
}
}
PHP program
<?php
for ($i = 1; $i <= 5; $i++)
{
for ($j = 1; $j <= $i ; $j++)
{
echo $j;
}
echo "</br>";
}
?>
Next TopicProgram to Print pattern 19
|