The program is written here to print the below series
# For loop is used here to print the series.
# The value of the first term of the series is 2.
# The value of the nth term of the series is: (13 × n × (n – 1)) / 2 + 2
For example, if the input is 5,
1st term: (13 × 1 × 0)/2 + 2 = 2
2nd term: (13 × 2 × 1)/2 + 2 = 15
3rd term: (13 × 3 × 2)/2 + 2 = 41
4th term: (13 × 4 × 3)/2 + 2 = 80
5th term: (13 × 5 × 4)/2 + 2 = 132
Therefore, the series will be: 2, 15, 41, 80, 132
INPUT: Number of terms
OUTPUT: The aforesaid series upto nth term
PROCESS:
Step 1: [Taking the input]
Read n [Number of terms]
Step 2: [Printing the series]
Set t<-0
Print "The series is: "
For i=1 to n repeat
Set t<-(13 × i × (i - 1)) / 2 + 2
Print t
[End of ‘for’ loop]
Step 3: Stop.
TIME COMPLEXITY:
for(i=1;i<=n;i++)----------------------------------- O(n)
{
t=(13 * i * (i - 1)) / 2 + 2;
printf("%d ",t);
}
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.
Related