Computer Science, asked by hanockgamer611, 5 months ago

don't spam and give correct answer


Attachments:

Answers

Answered by BrainlyProgrammer
2

Question:-

  • Program to print the following series
  • S=x/2+x/5+x/8....+x/20

Answer:-

This is done in JAVA Códe:-

package Códer;

import java.util.*;

public class Ser {

public static void main(String[] args) {

Scanner sc=new Scanner (System.in);

double s=0.0; int d=2;

System.out.println("Enter the value of x");

int x=sc.nextInt();

for(int i=1;i<=20;i++) {

s+=(double)x/d; d+=3;

}

System.out.println("Sum="+s);

}

}

Variable Description:-

  • s:- To store the sum
  • d:- local value to store the denominator
  • x:- to accept value of x from the user

Similar questions