Lab Task 4
Lab Task 4
Lab Report - 4
Submitted To
Submitted By
ID 2012020076
Batch 53(B)
Explanation: In this code, the number of rows in the half pyramid is controlled by the outer
loop. The user-inputted number is used as the starting point for iterating from 1 to the value of
rows. A new row is added to the half pyramid with each outer loop iteration. Each row of the
half pyramid's * is printed by the inner loop. It repeats from 1 to i, where i is the current value of
the variable in the outer loop. Each row of the half pyramid will contain more * than the row
before it as the outer loop proceeds because i grows. The specified number of * are printed for
the current row by the inner loop.
2) Program to print Inverted Half-Pyramid Using *:
Explanation: This code, The outer loop, which operates in reverse, also regulates the number of
rows in the half pyramid. With each iteration, it starts with i initialized to the value of the rows
and decreases i. This loop actually counts down from the number of rows provided to 1. Each
row of the half pyramid's * is printed by the inner loop. From 1 until the current value of i,
iterations are made. The number of * printed in each row also decreases as the outer loop
proceeds, resulting in the inverted pattern.
3) Program to print a Full-Pyramid using *:
Explanation: In this code, The outer loop controls the total number of rows in the pyramid. An
additional row in the entire pyramid is produced for each iteration of the outer loop. The first
inner loop is in responsible for printing the white space before each row's *. It prints a number of
spaces equal to rows - i.. The number of spaces written in each row reduces as the outer loop
continues. Printing the * in each row of the whole pyramid is done by the second inner loop. It
loops through 1 to 2 * i – 1. The quantity of * to be written in the current row is determined by
the formula 2 * i - 1. As the outer loop gets longer, there are more *.
4) Program to print Number diamond pattern:
Explanation: In this code, the diamond's upper portion's rows are controlled by the first outer
loop. In the upper portion of the diamond, a new row is produced after every loop. The first inner
loop prints a decreasing number of spaces as i rises that is equal to the number of rows - i. The
digits in each row of the diamond's upper portion are printed by the second inner loop. The
amount of digits to be printed in the current row is determined by i * 2 - 1, and iteration proceeds
from 1 to i * 2 - 1. The diamond's lower portion's lower rows are controlled by the second outer
loop. It iterates backwards, starting at row 1 and working its way down to row 1. In the lowest
portion of the diamond, a new row is produced with each iteration. First Inner Loop This loop
prints spaces before the numbers in each row of the bottom portion of the diamond, much as the
first inner loop in the upper section. Additionally, it displays a space count that reduces as i
increases and is equal to the number of rows. First Inner Loop, This loop prints the numbers in
each row of the bottom section of the diamond, much like the second inner loop does in the
upper part. The amount of numbers to be printed in the current row is determined by i * 2 - 1,
and iteration proceeds from 1 to i * 2 - 1. The numbers increase one after another.