0% found this document useful (0 votes)
8 views4 pages

Star Patterns Assignment

This document provides an assignment for an Introduction to Programming course focused on creating star patterns using nested loops in C++. It includes five specific tasks: printing a solid square, solid rectangle, solid right-angled triangle, solid inverted right-angled triangle, and a solid pyramid pattern, along with example C++ code for each. Students are instructed to write clean code, test their programs, and submit source files and output screenshots.

Uploaded by

Anime GAMING
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)
8 views4 pages

Star Patterns Assignment

This document provides an assignment for an Introduction to Programming course focused on creating star patterns using nested loops in C++. It includes five specific tasks: printing a solid square, solid rectangle, solid right-angled triangle, solid inverted right-angled triangle, and a solid pyramid pattern, along with example C++ code for each. Students are instructed to write clean code, test their programs, and submit source files and output screenshots.

Uploaded by

Anime GAMING
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

Nested Loops – Star Patterns Assignment

Course: Introduction to Programming (BSCS)


Topic: Nested Loops – Star Patterns
Instructions: 1. Write clean and readable C++ programs for each question. 2. Use nested loops to solve the
problems. 3. Test your programs with multiple inputs to ensure correctness. 4. Submit source code files
and output screenshots.

1. Solid Square Pattern


Question: Print a solid square of stars with 5 rows and 5 columns.

Output:

*****
*****
*****
*****
*****

C++ Code:

#include <iostream>
using namespace std;

int main() {
int rows = 5;
for(int i = 1; i <= rows; i++) {
for(int j = 1; j <= rows; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}

2. Solid Rectangle Pattern


Question: Print a solid rectangle of stars with 5 rows and 8 columns.

1
Output:

********
********
********
********
********

C++ Code:

#include <iostream>
using namespace std;

int main() {
int rows = 5, cols = 8;
for(int i = 1; i <= rows; i++) {
for(int j = 1; j <= cols; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}

3. Solid Right-Angled Triangle


Question: Print a right-angled triangle of stars.

Output:

*
**
***
****
*****

C++ Code:

#include <iostream>
using namespace std;

2
int main() {
int rows = 5;
for(int i = 1; i <= rows; i++) {
for(int j = 1; j <= i; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}

4. Solid Inverted Right-Angled Triangle


Question: Print an inverted right-angled triangle of stars.

Output:

*****
****
***
**
*

C++ Code:

#include <iostream>
using namespace std;

int main() {
int rows = 5;
for(int i = rows; i >= 1; i--) {
for(int j = 1; j <= i; j++) {
cout << "*";
}
cout << endl;
}
return 0;
}

3
5. Solid Cone (Pyramid) Pattern
Question: Print a solid pyramid (cone) of stars.

Output:

*
***
*****
*******
*********

C++ Code:

#include <iostream>
using namespace std;

int main() {
int rows = 5;
for(int i = 1; i <= rows; i++) {
for(int j = i; j < rows; j++) {
cout << " ";
}
for(int k = 1; k <= (2*i - 1); k++) {
cout << "*";
}
cout << endl;
}
return 0;
}

Notes for Students: - Use nested loops for rows and columns/stars.
- Outer loop → controls rows
- Inner loop → controls columns or stars
- Pyramid/cone requires two inner loops (spaces + stars)

You might also like