C++ program to display Pascal’s triangle using the Multi-Level inheritance
Write a C++ program to display Pascal’s triangle using the Multi-Level inheritance 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 38 39 40 41 42 43 44 45 46 |
#include<iostream> using namespace std; class A { protected: int r,s,c; }; class B:public A { protected: int i,j; }; class C:public B { public: int T4Tutorials_Print() { cout<<"num of rows:"; cin>>r; for(i=0;i<r;i++) { for(s=1;s<=r-i;s++) { cout<<" "
; } for(j=0;j<=i;j++) { if(j==0||i==0) { c=1; } else { c=c*(i-j+1)/j; } cout<<c<<" "; } cout<<endl; } } }; int main() { C obj; obj.T4Tutorials_Print(); } |
Output
FAQ
Pascal’s triangle using the Multi-Level inheritance in Object-oriented programing.
Pascal’s triangle using the Multi-Level inheritance but no inheritance in OOP.
Pascal’s triangle in C++ Â using the Multi-Level inheritance
Develop Pascal’s triangle program in C++ using the Multi-Level inheritance in Object-oriented programing.