C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Write a program to print the following pattern.1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 10 20 30 40 50 60 70 80 90 100 Algorithm
Solution:C Program:#include <stdio.h> int main() { int lines=10; int i=1; int j; for(i=1;i<=lines;i++){// this loop is used to print lines for(j=1;j<=i;j++){// this lop is used to print the table of the i printf("%d ",i*j); } printf("\n"); } return 0; } Output: 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 10 20 30 40 50 60 70 80 90 100 Java Program:public class pattern{ public static void main(String[] args){ int lines=10; int i=1; int j; for(i=1;i<=lines;i++){// this loop is used to print the lines for(j=1;j<=i;j++){// this loop is used to print lines System.out.print(i*j+" "); } System.out.println(""); } } } Output: 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 10 20 30 40 50 60 70 80 90 100 C# Program:using System; public class Program { public static void Main() { int lines=10; int i=1; int j; for(i=1;i<=lines;i++){// this loop is used to print the lines for(j=1;j<=i;j++){// this loop is used to print lines Console.Write(i*j+" "); } Console.WriteLine(""); } } } Output: 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 10 20 30 40 50 60 70 80 90 100 PHP Program:<?php $lines=10; $i=1; $j; for($i=1;$i<=$lines;$i++){// this loop is used to print lines for($j=1;$j<=$i;$j++){// this loop is used to print lines echo $i*$j; echo " "; } echo "<br>"; } ?> Output: 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 10 20 30 40 50 60 70 80 90 100 Python Program:lines=10 i=1 j=1 while i<=lines: # this loop is used to print the lines j=1 while j<=i: # this loop is used to print lines temp=i*j print(temp, end='', flush=True) print(" ", end='', flush=True) j=j+1; print(""); i=i+1; Output: 1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 10 20 30 40 50 60 70 80 90 100
Next TopicProgram to Print the Pattern 5
|