Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- void print_pyramid(int n){
- int k=0;
- check:
- if(n>=1 && n<=30){
- n*=2;
- for(int i=1;i<=n;i+=2){
- cout<<setw(n-k);
- for(int m=1;m<=i;m++){
- cout<<"*";
- }
- k++;
- cout<<endl;
- }
- }
- else{
- cout<<"Pick another height (must be between 1 and 30): ";
- cin>>n;cout<<endl;
- goto check;
- }
- }
- int main(){
- int n;
- cout<<"This program prints a 'pyramid' shape of \na specified height on the screen.\n\nhow high would you like the pyramid?: ";
- cin >> n;
- cout<<"\n";
- print_pyramid(n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement