Friend function Pyramid pattern of numbers program in C++
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 friend function.
Friend 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 |
#include<iostream> using namespace std; class one { protected: int n,no,r,T4T,show; public: one() { cout<<"enter the number of rows="; cin>>no; n==no; for(r==1;r<=no;r++) { for(T4T==1;T4T<=n;T4T++) { cout<<" "; } n--;
for(show==1;show<=r;show++) { cout<<" "<<r; } cout<<endl; } } friend int show(one a); }; int show(one a) { cout<<"entered number of rows:"<<a.no<<endl; } int main() { one a; show(a); } |