Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Function Overloading Programs on Series

 Design a class to overload a function series() as follows:


(a) void series(int x, int n): to display the sum of the series given below:

x1 + x2 + x3 + … + xn terms


(b) void series(int p): to display the following series:

0, 7, 26, 63, … p terms.


(c) void series(): to display the sum of the series given below:

1/2 + 1/3 + 1/4 + … + 1/10.


Program on Function  Overloading To Display Series

public class Series
{
 
    public void series(int x, int n)
    {
        double sum = 0L;
        for(int i = 1; i
        {
            sum=sum+Math.pow(x, i);
        }
        System.out.println("Sum of series is (1st Overloaded function)" + sum);
    }
    public void series(int p)
    {
        int term=0;
        System.out.print("\n2nd Overloaded function ");
        for(int i = 1; i
        {
            term = (int)(Math.pow(i, 3)-1);
            System.out.print(term + " ");
        }
    }
    public void series()
    {
        double sum = 0.0;
        for(int i = 2; i
            sum = sum+ 1.0 / i;
        System.out.println("\n\nSum of series is (3rd Overloaded function)" + sum);
    }
    
    public static void main(String args[])
    {
      Series ob = new Series();
      ob.series(2,4);
      ob.series(6);
      ob.series();  
    } 
  
}



This post first appeared on Tutorial Site On Computer Programming Languages F, please read the originial post: here

Share the post

Function Overloading Programs on Series

×

Subscribe to Tutorial Site On Computer Programming Languages F

Get updates delivered right to your inbox!

Thank you for your subscription

×