0% found this document useful (0 votes)
3 views5 pages

Lab Task 4

This lab report from Leading University details four programming exercises related to pyramid and diamond patterns using asterisks and numbers. Each program includes an explanation of the logic and structure behind the code, focusing on the use of loops to control the output format. The report is submitted by Mohammed Arif Mazeed Sikdar for the Compiler Design & Construction course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Lab Task 4

This lab report from Leading University details four programming exercises related to pyramid and diamond patterns using asterisks and numbers. Each program includes an explanation of the logic and structure behind the code, focusing on the use of loops to control the output format. The report is submitted by Mohammed Arif Mazeed Sikdar for the Compiler Design & Construction course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Computer Science and Engineering

Leading University, Sylhet

Lab Report - 4

Topic: Write Programs

Course Code CSE-3316

Course Title Compiler Design & Construction Sessional

Submitted To

Naeem Ahsan Chowdhury


Adjunct Lecturer
Department of Computer Science and Engineering

Submitted By

Name Mohammed Arif Mazeed Sikdar

ID 2012020076

Batch 53(B)

Department of Computer Science and Engineering

Submission Date: 04/09/2023


1) Program to print a Half-Pyramid using *:

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.

You might also like