A loop inside a loop
In this lesson: you will use nested loops to draw shapes and build tables.
Lesson 12
In this lesson: you will use nested loops to draw shapes and build tables.
In this lesson: you will use nested loops to draw shapes and build tables.
1тағ баландӣ = 3;2тағ бар = 5;3барои (тағ қатор = 1; қатор <= баландӣ; қатор++) {4тағ хат = "";5барои (тағ сутун = 1; сутун <= бар; сутун++) {6хат = хат + "*";7}8чоп(хат);9}
қатор). The inner loop makes the symbols of one row.хат ("line") starts again as an empty string ("").1тағ н = хонданиРақам();2барои (тағ и = 1; и <= н; и++) {3тағ хат = "";4барои (тағ ҷ = 1; ҷ <= и; ҷ++) {5хат += "#";6}7чоп(хат);8}
4
The inner loop runs и times: one symbol in the first row, two in the second, and so on.
Read the height and the width and print a rectangle made of *.
Input: Two numbers: the height, then the width.
Output: The rectangle.
Read the number н and print н lines: 1 on the first, 12 on the second, 123 on the third, and so on.
Input: One number: н (from 1 to 9).
Output: н lines.
Read the number н and print the н × н multiplication table: line и has the products from и × 1 to и × н, separated by spaces.
Input: One number: н.
Output: н lines.