TheAlgorithms-C-Plus-Plus/others/stairs_pattern.cpp

41 lines
748 B
C++
Raw Normal View History

2020-05-29 03:27:58 +08:00
/**
* @file
@brief This program is use to print the following pattern<pre>
\*\*
\*\*
\*\*\*\*
\*\*\*\*
\*\*\*\*\*\*
\*\*\*\*\*\*
\*\*\*\*\*\*\*\*
********</pre>
where number of pairs line is given by user
2020-04-19 23:20:42 +08:00
*/
2020-05-29 03:27:58 +08:00
#include <iostream>
/** main function */
int main()
{
2020-05-29 03:27:58 +08:00
int l, st = 2, x, r, z, n, sp;
std::cout << "enter Index ";
std::cin >> x;
z = x;
for (r = 1; r <= x; r++)
{
2020-05-29 03:27:58 +08:00
z = z - 1;
for (n = 1; n <= 2; n++)
{
for (sp = 1; sp <= z; sp++)
{
2020-05-29 03:27:58 +08:00
std::cout << " ";
}
for (l = 1; l <= st; l++)
{
2020-05-29 03:27:58 +08:00
std::cout << "*";
}
std::cout << std::endl;
}
st = st + 2;
}
2020-04-19 21:19:08 +08:00
}