Sum of the series Using an inline function in C++.
The inline function T4Tutorials_SERIES(int num)
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 T4Tutorials_SERIES(int num)
. Making inline means that compiler can replace the function definitions of inline T4Tutorials_SERIES(int num)
to the place where this function is called T4Tutorials_SERIES(n);
.
The compiler replaces the definition of inline functions at compile time instead of referring function definition at runtime.
Program of Sum of the series Using an inline function in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> using namespace std; inline T4Tutorials_SERIES(int num) { int k=9; int sum=0; for(int i=1;i<=num;i++) { sum=sum+k; k=k*10+9; } cout<<"The sum of T4Tutorials_SERIES is:"<<sum; }; int main() { int n; cout<<"Please enter the number of terms"; cin>>n; T4Tutorials_SERIES(n); //function called } |
Output
Please enter a number:
3
Hi, the sum of T4Tutorials_SERIES is:
1107