Hacker Rank SQL

Draw The Triangle 2 Solution

Hello Friends in this article i am gone to share Hacker Rank SQL Solutions with you | Draw The Triangle 2 Solution


Also Visit:ย  Draw The Triangle 1 Solution


 

Problem

P(R)ย represents a pattern drawn by Julia inย Rย rows. The following pattern representsย P(5):

* 
* * 
* * * 
* * * * 
* * * * *

Write a query to print the patternย P(20).

Solution โ€“ Draw The Triangle 2

MySQL Code
setย @rowย :=ย 0;
selectย repeat('*ย ',ย @rowย :=ย @rowย +ย 1)ย 
fromย information_schema.tablesย whereย @rowย <ย 20

 


What is a star in programming ?

In any programming language, star patterns are a common pattern widely used because it helps to improve logical thinking and flow control knowledge. You must use two or three loops to create a star pattern in the C language. The number of loops depends on the pattern that you need to create. For pattern, a minimum of two is used i.e. one for a row and one for a column. The First loop is called an outer loop that shows the rows, and the second loop is called an inner loop that shows columns.

Star patterns are a series of * or any other character used to create some pattern or any geometrical shape such as โ€“ square, triangle(Pyramid), rhombus, heart etc. These patterns are often prescribed by many programming books and are best for practicing flow control statement.

Many programmers around world extremely recommended pattern problems, to enhance logical thinking capabilities. As a novice programmer you must practice these patterns to get a good hands on logical thinking and program flow control.

 

Disclaimer: The above Problems are generated by Hacker Rank but the Solutions are Provided by NYANDER.COM. All Hacker Rank SQL Solutions Shared only for Educational and Learning Purpose.