Computer Science, asked by gopal2333, 3 months ago

Write a program to find the sum of the following series:
sum= (10/5)+(20/10)+(30/20)...........
n times.​

Answers

Answered by allysia
75

Program:

import java.util.Scanner;

public class oh {

public static void main(String[] args) {

 Scanner scan = new Scanner(System.in);

 System.out.print("Enter the value of n: ");

 int n = scan.nextInt();

 double sum = 0;

 int j = 10;

 double a = 5;

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

  sum = sum + ((j * i) / (a));

  a = a * 2;

 }

  System.out.print(sum );

}

}

NOTE: ignore the +"\t" portion I did it for debugging purpose and forgot to remove it later your program will work just fine without it.

Attachments:
Answered by BrainlyProgrammer
9

Question:-

  • WAP to find the sum of the following:-

sum=(10/5)+(20/10)+(30/20)

Code Logic:-

  • Numerators are the multiple of 10

Code Language:-

  • Not mentioned.
  • Done in Java, Python and Qbasic oo

Java Code:-

package Coder;

import java.util.*;

public class SumNumDeno

{

public static void main (String ar [])

{

Scanner sc=new Scanner (System.in);

int n=sc.nextInt();

int d=5;

double s=0;

for(int I=1;I<=n;I++)

{

s+=(10*I)/d;

d*=2;

}

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

}

}

Python Code:-

n=(int)(input("Enter a number of terms"))

s=0

d=5

for I in range(1,n+1):

s+=(10*I)/d

d=d*2

print("Sum=",s)

Qbasic code:-

CLS

PRINT"ENTER NO. OF TERMS"

INPUT N

D=5

FOR I=1 TO N

S=S+(10*I)/D

D=D*2

NEXT I

PRINT "SUM="+S

END

Similar questions