Search⌘ K

Solution Review: Display a Right-Angle Triangle

Explore how to display a right-angle triangle pattern using cout and the insertion operator in C++. Understand how to print lines with decreasing ampersands and add line breaks. This lesson helps you grasp basic output techniques and console formatting in C++ to build foundational programming skills.

We'll cover the following...

Solution #

C++
#include <iostream>
using namespace std;
int main() {
cout << "& & & & & &" << endl;
cout << "& & & & &" << endl;
cout << "& & & &" << endl;
cout << "& & &" << endl;
cout << "& &" << endl;
cout << "&";
}

Explanation

We use cout along with the insertion operator << to print text on the console. ...