0000 Series 10 | MyCareerwise

FOR FREE YEAR SOLVED


Description

Here the program is written to find the value of the series [(1^1)/1] + [(2^2)/2] + [(3^3)/3] + [(4^4)/4] + [(5^5)/5] + ... + [(n^n)/n]. Here, the number of terms ‘n’ is taken as input. A ‘for’ loop is used here to find the value of the series.

For example, if the input is 3 then the value of the series will be:

1+4/2+27/3 = 1+2+9=12

Algorithm

INPUT: The number of terms

OUTPUT: The value of the series

PROCESS:

Step 1: [Taking the input]

               Read n [Number of terms]

Step 2: [Finding the value of the series]

                Set s<-0

               [Finding the sum of the series]

               For i=1 to n repeat

                              Set s<-s+ii/i

               [End of ‘for’ loop]

               [Printing the sum of the series]

               Print "The sum of the series is: s"

Step 3: Stop.

Code

TIME COMPLEXITY:

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

                              s=s+pow(i,i)/i;

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

SPACE COMPLEXITY:

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