Computer Science, asked by shaikafham2, 7 months ago

write a program to sum the given sequences 1^2+3^2+5^2+n^2

Answers

Answered by amitnrw
1

Given :  1² + 3²  + 5²  +......     +........( upto n terms)

To Find :   sum

Solution:

1² + 3²  + 5²  +......     +........( upto n terms)

∑ (2n - 1)²

= ∑ ( 4n² - 4n   + 1)

= 4∑n²  - 4∑n  +  ∑1

= 4(n)(n+1)(2n+1)/6  - 4(n)n+1)/2   + n

=  (4/6) ( (n)(n+1) ) ( 2n + 1  - 3 )   + n

= (2/3) ( (n)(n+1) ) ( 2n  - 2 )   + n

= (4/3) (n)(n + 1)(n - 1)  + n

Start

Input  number in sequence    n  

Sum  =   4 (n )(n + 1) (n - 1) /3  +  n  

Print Sum

End

Another way use For loop

Start

Input number in sequence    n     ( integer )

m = 1

S = 0

 For  (  m <  2n- 1 ,    m = m + 2   )

{

 S = S  + m^2

}

Print  S

End

Learn more:

Write a a algorithm for a program that adds two digits numbers ...

https://brainly.in/question/14599411

write the next term of AP root2 ,root18........

https://brainly.in/question/8212323

Answered by anindyaadhikari13
1

\star\:\:\:\sf\large\underline\blue{Question:-}

Write a program to find the sum of the given series,

 \sf  sum =  {1}^{2}  +  {3}^{2}  +  {5}^{2} + ..  +  {(2n - 1)}^{2}

\star\:\:\:\sf\large\underline\blue{Source\:Code:-}

The code given below is written in Java Language.

import java.util.*;

class SeriesSum

{

public static void main(String s[])

{

Scanner sc=new Scanner(System.in);

System.out.print("Enter the total number of terms for the series sum: ");

int n=sc.nextInt();

int s=0;

for(int i=1;i<=2*n-1;i+=2)

s= s+(i*i) ;

System.out.println("The sum of the series is: "+s);

} // end of main()

} // end of class.

Similar questions