This C++ program displays a pattern made of asterisks (*). It takes the input value n from the user, which represents the number of rows in the pattern.
The first for loop is responsible for printing the upper half of the pattern, which consists of n rows. The i variable represents the row number. The inner for loop prints the required number of asterisks in each row, which increases by one for each successive row.
The second for loop is responsible for printing the lower half of the pattern, which also consists of n rows. The i variable represents the row number. The inner for loop prints the required number of asterisks in each row, which decreases by one for each successive row. It starts with printing n-1 asterisks in the first row, and ends with printing a single asterisk in the last row.
Overall, this program uses two nested for loops to print the pattern. The first loop prints the upper half of the pattern, and the second loop prints the lower half of the pattern. The inner loop in both cases prints the required number of asterisks in each row.
#include<iostream> using namespace std; int main() { int i,n,j; cout<<"\nEnter the value:"; cin>>n; for(i=1;i<=n;i++) { cout<<"\n"; for(j=1;j<=i;j++) { cout<<" *"; } } for(i=0;i<=n;i++) { cout<<"\n"; for(j=1;j<(n-i);j++) { cout<<" *"; } } return 0; }To download raw file Click Here
Enter the value:10 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions