Star Pattern in C++
Q.Write a C++ program for Star pattern?
#include <iostream>
using namespace std;
int main()
{
int n, i, j;
cout << "Enter number of rows: ";
cin >> n;
for (i = 0; i < n; i++)
{
for(j = 0; j < i+1; j++)
{
cout << "*";
}
cout << endl;
}
return 0;
}
Q. Write an algorithm to Star pattern using C++?
1. Start
2. Input: Read an integer `n` from the user (number of rows).
3. Initialize: Set `i = 0`.
4. Loop: Repeat while `i < n`:
- Set `j = 0`.
- Inner loop: Repeat while `j < i + 1`:
- Print `*` without a newline.
- Increment `j` by 1.
- After inner loop ends, print a newline character.
- Increment `i` by 1.
5. End when `i` equals `n`.
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com