Write a program in C++ to make such a pattern like a pyramid with a number that will repeat the number in the same row using class objects in OOP.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include<iostream> using namespace std; class pyramid { private: int r,sp,disp,n,no; public: show() { cout<<"enter a number="; cin>>no; n=no; } void sol() { for(r=1;r<=no;r++) { for(sp=1;sp<=n;sp++) { cout<<" "; } n--; for(disp=1;disp<=r;disp++) { cout<<" "<<r; } cout<<endl; } } }; int main() { pyramid ob; ob.show(); ob.sol(); } |