C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Program to print the following patternTo accomplish this task, we need to create two loops and the 2nd loop is to be executed according to the first loop. The first loop is responsible for printing the line breaks whereas the second loop is responsible for printing the stars (*). Algorithm
JAVApackage programs; import java.util.Scanner; public class Pattern1 { public static void main(String[] args) { int i,j,n=7; System.out.println("Right angle triangle"); for(i=1;i<n;i++) { for(j=1;j<=i;j++) { System.out.print(" *"); } System.out.println(""); } } } Pythonk = 1 n=7 for i in range(1, n): for j in range(i): print("*"), print("") C program#include <stdio.h> int main() { int i,j,n; n = 6; for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { printf(" *"); } printf("\n"); } } C# programusing System; public class Program { public static void Main(string[] args) { int n = 6; for (int row = 1; row <= 6; ++row) { for (int col = 1; col <= row; ++col) { Console.Write("*"); } Console.WriteLine(); } } } PHP program<?php $n=6; for ($i = 1; $i <= $n; $i++) { for ($j = 1; $j <= $i ; $j++) { echo '* '; } echo "</br>"; } ?>
Next TopicProgram to Print pattern 11
|