C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Program to show a triangle of numbers patternAlgorithm
JAVA programpackage programs; import java.util.Scanner; public class Pattern8 { public static void main(String[] args) { int size = 0; Character c; System.out.println(); size = 5; int i, j, k; for (i = 0; i < size + 1; i++) { for (j = size; j > i; j--) { System.out.print(" "); } for (k = 0; k < (2 * i - 1); k++) { System.out.print("*"); } System.out.println(); } } } Pythonfor i in range(1,6): for j in range(1, 6-i+1): print(" ", end='') for k in range(0, 2*i-1): print("*"), print("") C program#include <stdio.h> int main() { int i, j, k; for (i = 0; i < 5 + 1; i++) { for (j = 5; j > i; j--) { printf(" "); } for (k = 0; k < (2 * i - 1); k++) { printf("*"); } printf("\n"); } return 0; } C# programusing System; public class Program { public static void Main(string[] args) { int n, i, k, count = 1; n = 5; count = n - 1; for (k = 1; k <= n; k++) { for (i = 1; i <= count; i++) Console.Write(" "); count--; for (i = 1; i <= 2 * k - 1; i++) Console.Write("*"); Console.WriteLine(); } } } PHP program<?php for ($i=1; $i<=5; $i++) { for ($k=5; $k>$i; $k--) { echo "�"; } for($j=1;$j<=(2*$i)-1;$j++) { echo " *"; } echo "<br>"; } ?>
Next TopicProgram to Print pattern 1
|