Computer Science, asked by dony6443, 5 months ago

Write a program to find the sum of the series: a) s= 1/a + 2/a + 3/a +..........................n terms. b) s= 1+(1+2)+(1+2+3)+.........................+(1+2+3+........n).

Answers

Answered by BrainlyProgrammer
2

Answer:

This is done in JAVA...

Question:

  • write a program to find the sum of series:

a) s=1/a+2/a+3/a+.... nth term

Code:

System.out.println("Enter no. of terms") ;

n=sc.nextInt() ; //here u have to input no. of terms

System.out.println("Enter value of 'a'") ;

a=sc.nextInt() ; //here u have to enter value of 'a'

for(I=1;I<=n;I++) //loop from 1 to nth term

{

s=s+(I/a) ;

} //loop closed

System.out.println("Sum="+s) ;

___________________________________

b) s=1+(1+2)+(1+2+3)+...................nth term

System.out.println("Enter no. of terms") ;

System.out.println("Enter no. of terms") ;n=sc.nextInt() ; //here u have to input no. of terms

for(I=1;I<=n;I++) //loop from 1 to nth term

{

for(j=1;j<=I;j++)

{

p=p+j;

} //loop closed

s=s+p;

}

System.out.println("Sum="+s) ;

Answered by anindyaadhikari13
2

Question 1.

Write a program in Java to find the sum of the series.

S=1/a+2/a+3/a+.... n/a

Program:-

import java.util.*;

class Sum

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the value of n: ");

int n=sc.nextInt();

System.out.print("Enter the value of a: ");

double a=sc.nextDouble(), s=0;

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

s+=i/a;

System.out.println("Sum is: "+s);

}

}

Question 2.

Write a program in Java to find the sum of the series.

S=1+(1+2)+(1+2+3)+(1+2+3+4)

Program:-

import java.util.*;

class Sum

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the value of n: ");

int n=sc.nextInt(), s=0;

int a=0;

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

{

a+=i;

s+=a;

}

System.out.println("Sum is: "+s);

}

}

Similar questions