Techiio-author
Started by Anik AdhikaryMay 4, 2022

Open
How to write a C++ program to draw a pattern ?

4 VIEWES 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 4 VIEWES SHARE

somebody please help me.......

blogpost

2 Replies

Techiio-commentatorChris Gill replied 3 months ago0 likes0 dislikes

#include <iostream>

using namespace std;

int main()

{

int rows;

cout << "Enter number of rows: ";

cin >> rows;

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

{

for(int space = 0; space < rows-i; ++space)

cout << " ";

for(int j = i; j <= 2*i-1; ++j)

cout << "* ";

for(int j = 0; j < i-1; ++j)

cout << "* ";

cout << endl;

}

return 0;

}

Techiio-commentator replied 3 months ago0 likes0 dislikes
#include<iostream>
using namespace std;
int main()
{
int n, s, i, j;
cout << "Enter number of rows: ";
cin >> n;
for(i = n; i >= 1; i--)
{
//for loop to put space
for(s = i; s < n; s++)
cout << " ";
//for loop for displaying star
for(j = 1; j <= i; j++)
cout << "* ";
// ending line after each row
cout << "\n";
}
return 0;
}
You must be Logged in to reply
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance