Write a program to find the sum of the series given below, taking the values ‘a’ and ‘n’ from
the user.
S = a/2 + a/3 + a/4 + .....................to n.
Answers
Answered by
1
Language:
Python
Program:
a=int(input("Enter the value of a: "))
n=int(input("Enter the value of n: "))
sum=0
for i in range(2,n+2):
sum+= a/i
print(sum)
Output:
Enter the value of a: 2
Enter the value of n: 3
2.1666666666666665
Explanation:
- a saves input value of a in the expression mentioned.
- sum saves the sum.
- using for loop we produce a/i which starts from 2 for n times.
Similar questions