Advertisement

Responsive Advertisement

How To Print Star Pattern in C ++

 Here is one way you can print a star pattern in C++:

#include <iostream> 
int main()
{
for (int i = 0; i < 5; i++)
 {
for (int j = 0; j <= i; j++) { std::cout << "*"
 } std::cout << std::endl; } 
return 0; }




This will print the following pattern:

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

To modify the pattern, you can change the number of rows, the number of stars in each row, and the character being printed (e.g. to print a different character or to print multiple characters per iteration).

Post a Comment

0 Comments