write a program in java to display the first 10 terms of the following series 1/2+2/3+3/4+........................+19/20
Answers
Answered by
2
Series:-
- 1/2+2/3+3/4+......+19/20
Logic:-
s=s+(I/(I+1))
Code:-
package Coder;
public class Series {
public static void main(String[] args) {
int i;
double s=0;
for(i=1;i<20;i++)
{
if(i!=19)
System.out.print(i+"/"+(i+1)+"+");
else
System.out.print(i+"/"+(i+1));
s+=(double)i/(i+1);
}
System.out.println("\nSum="+s);
}
}
Variable Description:-
- i-----Loop variable
- s----to store the sum of the series
•Output attached
Attachments:
Similar questions