Write a program in C++ to find the sum of the series using the inline function.
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 |
#include<iostream> #include<math.h> using namespace std; class T4Tutorials_Series_Class { protected: int a,sum,c; int i,x,n,T4Tutorials_Variable1,T4Tutorials_Variable2; public: int in(); int sol(); }; inline int T4Tutorials_Series_Class::in() { cout<<"enter the value of a="<<endl; cin>>a; cout<<"enter the num of term"<<endl; cin>>n; sum=a; x=-1; cout<<"the value of T4Tutorials_Series_Class"<<endl; cin>>a; } inline int T4Tutorials_Series_Class::sol() { for(i=1;i<n;i++) { c=(2*i+1); T4Tutorials_Variable1=pow(a,c); T4Tutorials_Variable2=T4Tutorials_Variable1*x; cout<<T4Tutorials_Variable2<<endl; sum=sum+T4Tutorials_Variable2; x=x*(-1); } cout<<"sum of T4Tutorials_Series_Class"<<sum<<endl; } int main() { T4Tutorials_Series_Class ob; ob.in(); ob.sol(); } |
Output