Computer Science, asked by madhavip725, 7 months ago

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

Answers

Answered by jaiswardishita
5

Answer:

take a loop with the x will be of the users (given) take an integer i to run the loop

class a1

{

void main(int x , int n)

{

int s =0;

for(int i=1; i<=n; i++)

{ // for starts

s=s+x*i;

} // for ends

sopln("sum "+s); // sum of the series

}

}

Explanation:

I hope it helps

Answered by Anonymous
2

class sum_of_nth {

   public static void main(String[] args) {

       Sum(1000,561545);

   }

   public static void Print(Object _object_) {

       System.out.print(_object_);

   }

   public static void Sum(long x, long n) {

       for (long i = 0; i < n; i++) {

           Print(x + " + ");

       }

       Print("0 = " + (x * n));

   }

}

Similar questions