0% found this document useful (0 votes)
83 views1 page

Loops CPP

This document contains C++ code definitions for four functions - printRectangle, printRight, printRightJustified, and printIsosceles. Each function uses nested for loops to print different patterns of asterisks to the console, with printRectangle printing a rectangle, printRight printing a right-justified triangle, printRightJustified printing a right-justified triangle with spaces, and printIsosceles printing an isosceles triangle. The functions take integer arguments to determine the size and shape of the patterns printed.

Uploaded by

Alexandru Donțu
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)
83 views1 page

Loops CPP

This document contains C++ code definitions for four functions - printRectangle, printRight, printRightJustified, and printIsosceles. Each function uses nested for loops to print different patterns of asterisks to the console, with printRectangle printing a rectangle, printRight printing a right-justified triangle, printRightJustified printing a right-justified triangle with spaces, and printIsosceles printing an isosceles triangle. The functions take integer arguments to determine the size and shape of the patterns printed.

Uploaded by

Alexandru Donțu
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/ 1

/**

* loops.cpp
*
* EECS 183
* Lab 4: Loops exercises

*/

#include "loops.h"
#include <iostream>

using namespace std;

void printRectangle(int rows, int cols) {


for(int i = 1; i <= rows; i++){
for(int j = 1; j <= cols; j++){
cout << "*";
}
cout << endl;
}
}

void printRight(int n) {
for(int i=1; i <= n; i++){
for(int j = 0; j < i; j++){
cout << "*";
}
cout << endl;
}
}

void printRightJustified(int n) {
for(int i=n-1; i >= 0; i--){
for(int j = 0; j < i; j++){
cout << " ";
}
for(int k = i; k < n; k++){
cout << "*";
}
cout << endl;
}
}

void printIsosceles(int n) {
int m = n;
for(int i = 0; i < n; i++){
for(int j = m; j > 1; j--){
cout << " ";
}

for(int k = 0; k <= i * 2; k++){


cout << "*";
}
m--;
cout << endl;
}

This study source was downloaded by 100000841455145 from CourseHero.com on 02-09-2022 16:21:55 GMT -06:00

https://www.coursehero.com/file/38187622/loopscpp/
Powered by TCPDF (www.tcpdf.org)

You might also like