A C++ program to print the below pattern
*
**
***
****
*****
****
***
**
*
The below pattern program is combination of other two patterns which you studied in earlier
*
**
***
****
*****
**
***
****
*****
*****
****
***
**
*
****
***
**
*
Code
#include <iostream>
using namespace std;
int main() {
for(int i=1;i<=5;i++){ //1st loop holds count
for(int j=1;j<=i;j++){ //2nd loop prints i stars
cout<<"*";
}
cout<<endl;
}
//this 3rd loop holds count in reverse and start from 4 as we already printed 5 stars
for(int i=4;i>0;i--){
for(int j=1;j<=i;j++){ //4th loop prints i stars
cout<<"*";
}
cout<<endl;
}
return 0;
}
Output
*
**
***
****
*****
****
***
**
*
0 Comments