Computer Science, asked by themayurakshi, 10 months ago

WAP in java to print the sum of the following series : S= 2+6+30+260+ ........ + n terms​

Answers

Answered by siddhusujhatha
1

Answer:import java.util.Scanner;

public class Exercise11 {

   

 public static void main(String[] args)

{

  int i, n, sum=0;

  {

  Scanner in = new Scanner(System.in);  

       System.out.print("Input number: ");  

        n = in.nextInt();

}

 System.out.println("The first n natural numbers are : "+n);

 

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

  {

    System.out.println(i);

    sum+=i;

  }

System.out.println("The Sum of Natural Number upto "+n+ " terms : " +sum);

}

}

Copy

Sample Output:

Input number: 7                                                                                                

The first n natural numbers are : 7                                                                            

1                                                                                                      

2                                                                                                      

3                                                                                                      

4                                                                                                      

5                                                                                                      

6                                                                                                      

7                                                                                                      

The Sum of Natural Number upto n terms : 28    

Flowchart:

Flowchart: Java Conditional Statement Exercises - Display n terms of natural numbers and their sum

Explanation:

Answered by rajeshnehra1983
0

Answer:

Sn=n/2(2+an)

Explanation:

Sn=Sum of n term

For ex. : 2+6+30+260.....

n=nth term means that how much terms are there

an=last term

Similar questions