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

ALL LOOP PROGRAMS

The document contains various functions for generating different patterns using loops in a programming language. Patterns include pyramid, inverted pyramid, right-angled triangle, diamond, Floyd's triangle, Pascal's triangle, hollow square, number triangle, alphabet, and checkerboard. A main function demonstrates the usage of these pattern functions with a specified number of rows and size.

Uploaded by

Zaka Malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

ALL LOOP PROGRAMS

The document contains various functions for generating different patterns using loops in a programming language. Patterns include pyramid, inverted pyramid, right-angled triangle, diamond, Floyd's triangle, Pascal's triangle, hollow square, number triangle, alphabet, and checkerboard. A main function demonstrates the usage of these pattern functions with a specified number of rows and size.

Uploaded by

Zaka Malik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ALL LOOP PROGRAMS

void pyramidPattern(int rows) {

for (int i = 1; i <= rows; i++) {

print(' ' * (rows - i) + '*' * (2 * i - 1));

void invertedPyramidPattern(int rows) {

for (int i = rows; i >= 1; i--) {

print(' ' * (rows - i) + '*' * (2 * i - 1));

void rightAngledTrianglePattern(int rows) {

for (int i = 1; i <= rows; i++) {

print('*' * i);

void diamondPattern(int rows) {

for (int i = 1; i <= rows; i++) {

print(' ' * (rows - i) + '*' * (2 * i - 1));

for (int i = rows - 1; i >= 1; i--) {

print(' ' * (rows - i) + '*' * (2 * i - 1));

}
void floydsTriangle(int rows) {

int num = 1;

for (int i = 1; i <= rows; i++) {

String row = '';

for (int j = 1; j <= i; j++) {

row += '$num ';

num++;

print(row);

void pascalsTriangle(int rows) {

for (int i = 0; i < rows; i++) {

List<int> row = List.filled(i + 1, 1);

for (int j = 1; j < i; j++) {

row[j] = row[j - 1] * (i - j + 1) ~/ j;

print(row.join(' '));

void hollowSquarePattern(int size) {

for (int i = 0; i < size; i++) {

String row = '';

for (int j = 0; j < size; j++) {

if (i == 0 || i == size - 1 || j == 0 || j == size - 1) {

row += '*';

} else {
row += ' ';

print(row);

void numberTrianglePattern(int rows) {

for (int i = 1; i <= rows; i++) {

String row = '';

for (int j = 1; j <= i; j++) {

row += '$j ';

print(row);

void alphabetPattern(int rows) {

for (int i = 0; i < rows; i++) {

String row = '';

for (int j = 0; j <= i; j++) {

row += String.fromCharCode(65 + j) + ' ';

print(row);

void checkerboardPattern(int size) {

for (int i = 0; i < size; i++) {


String row = '';

for (int j = 0; j < size; j++) {

row += ((i + j) % 2 == 0) ? '*' : ' ';

print(row);

void main() {

int rows = 5;

int size = 5;

print("Pyramid Pattern:");

pyramidPattern(rows);

print("\nInverted Pyramid Pattern:");

invertedPyramidPattern(rows);

print("\nRight Angled Triangle Pattern:");

rightAngledTrianglePattern(rows);

print("\nDiamond Pattern:");

diamondPattern(rows);

print("\nFloyd's Triangle Pattern:");

floydsTriangle(rows);

print("\nPascal's Triangle Pattern:");

pascalsTriangle(rows);
print("\nHollow Square Pattern:");

hollowSquarePattern(size);

print("\nNumber Triangle Pattern:");

numberTrianglePattern(rows);

print("\nAlphabet Pattern:");

alphabetPattern(rows);

print("\nCheckerboard Pattern:");

checkerboardPattern(size);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy