Interview Question

Interview Herndon, VA

write a program to print pyramid

Answer

Interview Answer

1 Answer

0

#include <iostream> using namespace std; class pyramid(int _height){ private: int height; public: void setHeight{height = _height;} void print( int starCount = 1; for( int i = 0; i < height ; i++){ for(int j = 0 ; j < (height - i); j++){cout << " " ; } for(int k = 0; k < starcount ; k++){cout <<"*"; } cout<< endl; starCount += 2; } } } int main(){ Pyramid myP; myP.setHeight(30); myP.print(); }

Anonymous on Mar 24, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.