Write the program to find the sum of the following series
S=a/2+a/5+a/8+a/11+……….+a/20
Answers
Answer:
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value for A ");
double input = sc.nextFloat();
double sum=0;
for(int i=2;i<=20;i+=3) // to divide by 2,5,8 so on that is why increase by 3 to i
{
sum+=input/i;
}
System.out.println(sum );
}
}
If you have any question feel free to ask me. :)
no problem :) always ready to share my experience and knowledge
+1
Sure I will just check it out :)
0
I have posted 1 more question can u give the program for that @Giriraj Bhagat
0000
0
I have posted the answers for both of your questions. If you have any querries do let me know
def series(a):
_sum = 0
for i in range(2, 21, 3):
_sum += a / i
return _sum
print("result:", series((a := int(input("a: ")))))