C++ program : To find the harmonic series using Inline function




#include<iostream.h>
#include<conio.h>
class harmonic
{
   public:
   float ans;
   harmonic()
   {
      ans=0;
   }
   float process(float i)
   {
      if(i==0)
         return 0;
      ans+=process(i-1);
      return 1/i;
   }
};
int main()
{
   clrscr();
   float n;
   cout<<"Enter the Value of n:";
   cin>>n;
   harmonic ob;
   ob.process(n+1);
   cout<<"The Answer : "<<ob.ans;
   getch();
   return 0;
}


// Special Thanks to Gostkiller ( Midhul )...

Class diagram 

(click image to view large)

 

 



Related Posts:

1 comment: