Write a program in C++ to make such a pattern like a pyramid with a number which will repeat the number in the same row using inlne function.
Inline function Pyramid pattern in C++
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 38 39 |
#include<iostream> using namespace std; class pyramid { private: int r,T4Tutorials,print,n,no; public: int in(); int sol(); }; inline int pyramid::in() { cout<<"enter the number of rows"; cin>>no; n=no; } inline int pyramid:: sol() { for(r=1;r<=no;r++) { for(T4Tutorials=1;T4Tutorials<=n;T4Tutorials++) { cout<<" "; } n--; for(print=1;print<=r;print++) { cout<<" "<<r; } cout<<endl; } } int main() { pyramid ob; ob.in(); ob.sol(); } |