0000 Series 3 | MyCareerwise

FOR FREE YEAR SOLVED


Description

The program is written here to find the value of the series 1 + 3^2/3^3 + 5^2/5^3 + 7^2/7^3 + ... till N terms. The value of ‘n’ is taken as input. If the value of ‘n’ is 2 then the value will be:

1+ 3^2/3^3 = 1+1/3 = 1.3333

Using the ‘for’ loop the value of the series is calculated.

Algorithm

INPUT: The number of terms 

OUTPUT: The sum of the series

PROCESS:

Step 1: [Taking the input]

               Read n [number of terms]

Step 2: [Calculating the sum of the series]

               Set s<-0

               Set t<-1

               [Finding the sum]

               For i = 1 to n repeat 

                              Set s <- s + (t×t)/(t×t×t)

                              Set t<-t+2 

               [End of ‘for’ loop]

               [Printing the result]

               Print "The sum of the series is: s"

Step 3: Stop.

Code

TIME COMPLEXITY:

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

               { 

                              s = s + (t*t)/(t*t*t);

                              t+=2; 

               } 

The time complexity of this program is O(n) where ‘n’ is the number of terms of the series.

SPACE COMPLEXITY:

The space complexity of this program is O(1) as it requires a constant number of memory spaces for any given input.