TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Program To Print Pattern 4

Program To Print Pattern 4 on fibonacci, factorial, prime, armstrong, swap, reverse, search, sort, stack, queue, array, linkedlist, tree, graph, pattern, string etc.

<< Back to PROGRAM

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

  • STEP 1: START
  • STEP 2: SET lines =10
  • STEP 3: SET i=1
  • STEP 4: REPEAT STEP 5 to 9 UNTIL i is less than or equals to lines
  • STEP 5: SET j=1
  • STEP 6: REPEAT STEP 7 UNTIL j is less than or equals to i
  • STEP 7: PRINT i*j and SET j = j + 1
  • STEP 8: PRINT new line
  • STEP 9: SET i = i + 1
  • STEP 10: EXIT

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





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf