FOR FREE CONTENT


Description

The program is written here to find the sum of the series 

 

The number of terms is taken as input and then using a for loop the sum of the series is calculated.

 

If the value of n is 3 then the sum will be calculated as:

Algorithm

INPUT: Number of terms

OUTPUT: Sum of the Series

PROCESS:

Step 1: [Taking the input]

               Read n [number of terms]

Step 2: [Finding the sum]

Set s <- 0

Set f <- 1 

               [Finding the sum]

               for i = 1 to n repeat 

                              Set f<-f × i

                              Set s <- s + (i / f) 

               [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)

               { 

                              f=f * i; 

                              s = s + (i / f); 

               } 

 

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 the program is O(1) as it requires a constant number of memory spaces for any given input.