Given a number **N**, the task is to print **N** rows where every **K ^{th}** row consists of the multiplication table of

**K**up to

**K**term.

^{th}**Examples:**

Input:N = 3

Output:

1

2 4

3 6 9

Explanation:

In the above series, in every K^{th}row, multiplication table of K upto K terms is printed.

Input:N = 5

Output:

1

2 4

3 6 9

4 8 12 16

5 10 15 20 25

**Approach:** The idea is to use two for loops to print the multiplication table. The outer loop in ‘i’ serves as the value of ‘K’ and the inner loop in ‘j’ serves as the terms of the multiplication table of every ‘i’. Each term in the table of ‘i’ can be obtained with the formula ‘i * j’.

Below is the implementation of the above approach:

## C++

`// C++ program to print multiplication table ` `// till N rows where every Kth row ` `// is the table of K up to Kth term ` `#include <iostream> ` `using` `namespace` `std; ` ` ` `// Function to print the multiplication table ` `// upto K-th term ` `void` `printMultiples(` `int` `N) ` `{ ` ` ` `// For loop to iterate from 1 to N ` ` ` `// where i serves as the value of K ` ` ` `for` `(` `int` `i = 1; i <= N; i++) ` ` ` `{ ` ` ` ` ` `// Inner loop which at every ` ` ` `// iteration goes till i ` ` ` `for` `(` `int` `j = 1; j <= i; j++) ` ` ` `{ ` ` ` ` ` `// Printing the table value for i ` ` ` `cout << (i * j) << ` `" "` `; ` ` ` `} ` ` ` ` ` `// New line after every row ` ` ` `cout << endl; ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `N = 5; ` ` ` ` ` `printMultiples(N); ` ` ` ` ` `return` `0; ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

## Java

`// Java program to print multiplication table ` `// till N rows where every Kth row ` `// is the table of K up to Kth term ` ` ` `class` `GFG { ` ` ` ` ` `// Function to print the multiplication table ` ` ` `// upto K-th term ` ` ` `public` `static` `void` `printMultiples(` `int` `N) ` ` ` `{ ` ` ` `// For loop to iterate from 1 to N ` ` ` `// where i serves as the value of K ` ` ` `for` `(` `int` `i = ` `1` `; i <= N; i++) { ` ` ` ` ` `// Inner loop which at every ` ` ` `// iteration goes till i ` ` ` `for` `(` `int` `j = ` `1` `; j <= i; j++) { ` ` ` ` ` `// Printing the table value for i ` ` ` `System.out.print((i * j) + ` `" "` `); ` ` ` `} ` ` ` ` ` `// New line after every row ` ` ` `System.out.println(); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main(String args[]) ` ` ` `{ ` ` ` `int` `N = ` `5` `; ` ` ` ` ` `printMultiples(N); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 program to pr multiplication table ` `# till N rows where every Kth row ` `# is the table of K up to Kth term ` ` ` `# Function to pr the multiplication table ` `# upto K-th term ` `def` `prMultiples(N): ` ` ` ` ` `# For loop to iterate from 1 to N ` ` ` `# where i serves as the value of K ` ` ` `for` `i ` `in` `range` `(` `1` `, N ` `+` `1` `): ` ` ` ` ` `# Inner loop which at every ` ` ` `# iteration goes till i ` ` ` `for` `j ` `in` `range` `(` `1` `, i ` `+` `1` `): ` ` ` ` ` `# Printing the table value for i ` ` ` `print` `((i ` `*` `j), end ` `=` `" "` `) ` ` ` ` ` `# New line after every row ` ` ` `print` `() ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` `N ` `=` `5` ` ` ` ` `prMultiples(N) ` ` ` `# This code is contributed by mohit kumar 29 ` |

*chevron_right*

*filter_none*

## C#

`// C# program to print multiplication table ` `// till N rows where every Kth row ` `// is the table of K up to Kth term ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to print the multiplication table ` ` ` `// upto K-th term ` ` ` `public` `static` `void` `printMultiples(` `int` `N) ` ` ` `{ ` ` ` `// For loop to iterate from 1 to N ` ` ` `// where i serves as the value of K ` ` ` `for` `(` `int` `i = 1; i <= N; i++) { ` ` ` ` ` `// Inner loop which at every ` ` ` `// iteration goes till i ` ` ` `for` `(` `int` `j = 1; j <= i; j++) { ` ` ` ` ` `// Printing the table value for i ` ` ` `Console.Write((i * j) + ` `" "` `); ` ` ` `} ` ` ` ` ` `// New line after every row ` ` ` `Console.WriteLine(); ` ` ` `} ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main(String []args) ` ` ` `{ ` ` ` `int` `N = 5; ` ` ` ` ` `printMultiples(N); ` ` ` `} ` `} ` ` ` `// This code is contributed by Rajput-Ji ` |

*chevron_right*

*filter_none*

**Output:**

1 2 4 3 6 9 4 8 12 16 5 10 15 20 25

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Nth term where K+1th term is product of Kth term with difference of max and min digit of Kth term
- Sum of series till N-th term whose i-th term is i^k - (i-1)^k
- Sum of the series 1, 2, 4, 3, 5, 7, 9, 6, 8, 10, 11, 13.. till N-th term
- Check if it is possible to create a matrix such that every row has A 1s and every column has B 1s
- Program to get the Sum of series: 1 - x^2/2! + x^4/4! -.... upto nth term
- Program to print tetrahedral numbers upto Nth term
- Program to print pentatope numbers upto Nth term
- Program for sum of cosh(x) series upto Nth term
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series where each term differs by 6 and 2 alternately
- Nth term of a sequence formed by sum of current term with product of its largest and smallest digit
- Count sequences of length K having each term divisible by its preceding term
- First term from given Nth term of the equation F(N) = (2 * F(N - 1)) % 10^9 + 7
- Nth term of given recurrence relation having each term equal to the product of previous K terms
- Smallest missing non-negative integer upto every array index
- Program to print multiplication table of a number
- Recursive Program to print multiplication table of a number
- Print the sequence of size N in which every term is sum of previous K terms
- Space between two rows in a table using CSS?
- Apply function to every row in a Pandas DataFrame

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.