C++ program of inline function to display a pattern for a number of rows
Write a C++ program of inline function to display a pattern for a number of rows using a number which will start with the number 1 and the first and the last number of each row will be 1. The pattern is as follows:
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 | #include<iostream> #include<conio.h> using namespace std; class A { public: int i,j,k,l,n; public: int T4Tutorials_pattern(); }; inline A::T4Tutorials_pattern() { cout <<"enter num of rows:"; cin>>n; for(i=1;i<=n;i++) { for(l=1;l<=n-i;l++ ) { cout<<" "; } for(j=1;j<=i;j++) { cout<<j; } for(k=i-1;k>=1;k--) { cout<<k; } cout<<endl; } } int main() { A obj; obj.T4Tutorials_pattern(); } |