This C++ program displays a pattern made of asterisks (*). It takes the input value a 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 a rows. The i variable represents the row number. The inner for loop prints the required number of spaces in each row, which is equal to a. The next 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 a rows. The i variable represents the row number. The first inner for loop prints the required number of spaces in each row, which starts with a single space for the first row and increases by one for each successive row. The next inner for loop prints the required number of asterisks in each row, which starts with a-i asterisks in the first row and decreases by one for each successive row. The third inner for loop prints a asterisks in each row. The fourth inner for loop prints the required number of asterisks in each row, which is equal to (a-i) asterisks for the first row and increases by one for each successive row.
Overall, this program uses four 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 loops in both cases print the required number of spaces and asterisks in each row.
#include<iostream> using namespace std; int main() { int i,n,a; cout<<"\nEnter the value:"; cin>>a; for(i=1;i<=a;i++) { cout<<"\n"; for(n=1;n<=a;n++) { cout<<" "; } for(n=1;n<=i;n++) { cout<<" *"; } } for(i=1;i<=a;i++) { cout<<"\n"; for(n=1;n<=i;n++) { cout<<" "; } for(n=1;n<=(a-i);n++) { cout<<" *"; } for(n=1;n<=a;n++) { cout<<" *"; } for(n=1;n<=(a-i);n++) { cout<<" *"; } } }To download raw file Click Here
Enter the value:10 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions