Write a C++ program to display Pascal’s triangle using the inline function.
The inline function inline A::T4Tutorials_pattern()
 helps to increase the execution time of a program. The programmer can make a request to the compiler to make the inline function as inline A::T4Tutorials_pattern()
.
Making inline means that compiler can replace the function definitions of inline A::T4Tutorials_pattern()
with the place where this function is called obj.T4Tutorials_pattern();
.
The compiler replaces the definition of inline functions at compile time instead of referring function definition at runtime.
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 A { protected: int r,s,i,j,c; public: int T4Tutorials_pattern(); }; inline A::T4Tutorials_pattern() { cout<<"Enter num of rows:"<<endl; 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() { A obj; obj.T4Tutorials_pattern(); } |