[Question 7] ICSE 2016 Computer Application Solved - Sum Series

Question 7.


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

(i) void SumSeries(int n, double x) - with one integer argument and one double
     argument to find and display the sum of the series given below:

            s = x/1 - x/2 + x/3 - x/4 + x/5... ... ... to n terms

(ii) void SumSeries() - To find and display the sum of the following series:

           s=1 + (1*2)  + (1*2*3) + ... ... ... +  (1*2*3*4... ... ...*20)



SOURCE CODE

import java.io.*;
import java.util.*;
public class ICSE2016_Ques7_Series
{
    double sum;
    void SumSeries(int n,double x)
    {
        for(int i=1;i<=n;i++)
        {
            if(i%2!=0)
            {
                sum=sum+(x/i);
            }
            else if(i%2==0)
            {
                sum=sum-(x/i);
            }
        }
        System.out.println("OUTPUT for first series ");
        System.out.println("Sum when x=6, n=6 : "+sum);
    }

    void SumSeries()
    {
        for(int i=1;i<=20;i++)
        {
            int f=1;
            for(int j=1;j<=i;j++)
            {
                f=f*j;
            }
            sum=sum+f;
        }
        System.out.println("OUTPUT for second series ");
        System.out.println("Sum = "+sum);
    }
}


OUTPUT




If you have any question then leave a comment below I will do my best to answer that question.


Comments

  1. Write a program to accept a number and check whether the number is palindrome
    or not by using the function name reverse (int n). The function returns the reversed
    number to the main program that checks the palindrome number.

    ReplyDelete

Post a Comment

Popular posts from this blog

Pattern of your own name.

[Question 3] ISC 2017 Computer Practical Paper Solved – Caesar Cipher.

ISBN Number.