Advertisement
RnD

C++ pyramid

RnD
Dec 9th, 2012
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. void print_pyramid(int n){
  6.     int k=0;
  7.     check:
  8.     if(n>=1 && n<=30){
  9.         n*=2;
  10.         for(int i=1;i<=n;i+=2){
  11.             cout<<setw(n-k);
  12.             for(int m=1;m<=i;m++){
  13.                 cout<<"*";
  14.             }
  15.             k++;
  16.             cout<<endl;
  17.         }
  18.     }
  19.     else{
  20.         cout<<"Pick another height (must be between 1 and 30): ";
  21.         cin>>n;cout<<endl;
  22.         goto check;
  23.     }
  24. }
  25.  
  26. int main(){
  27.     int n;
  28.  
  29.     cout<<"This program prints a 'pyramid' shape of \na specified height on the screen.\n\nhow high would you like the pyramid?: ";
  30.     cin >> n;
  31.     cout<<"\n";
  32.     print_pyramid(n);
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement