190k views
2 votes
2. Write a program that askes the user to enter a positive number not greater than 10.the program then must display the triangle on the screen using character X.The number entered by the user will be the length of vertical side of the triangle.for example if the user enter 5 the program should display the following; X XX XXX XXXX XXXXX IF THE USER ENTER 8 THEN THE PRGRAM SHOULD DISPLAY THE FOLLOWING; X XX XXX XXXX XXXXX XXXXXX XXXXXXX XXXXXXXX

1 Answer

5 votes

Answer:

it will display in this pattern X XX XXX XXXX XXXXX

#include <iostream>

using namespace std;

int

main ()

{

int a,i, j=0;

cout << "enter number for length of triangle";

cin >> i;

for ( a = 1; a <= i; a++)

{

for (j = 1; j <= a; j++)

{

cout << "X";

}

cout<<" ";

}

}

for this

X

XX

XXX

XXXX

XXXXX

#include <iostream>

using namespace std;

int

main ()

{

int a,i, j=0;

cout << "enter number for length of triangle";

cin >> i;

for ( a = 1; a <= i; a++)

{

for (j = 1; j <= a; j++)

{

cout << "X";

}

cout<<endl;

}

}

User Andrew Marsh
by
5.0k points