Series program using BlueJ where a separate function is used to calculate factorial value.
The series is x!/10 + (x+2)!/15 + (x+4)!/20 + (x+n)!/100
Back To BlueJ Series Display Programs Home Page: CLICK HERE
The series is x!/10 + (x+2)!/15 + (x+4)!/20 + (x+n)!/100
import java.util.*;
class Search
{
int
x,c=10,n;
double sum=0;
int
j=10;
Scanner
sc=new Scanner(System.in);
public void assign()
{
System.out.print("\nEnter value of 'x':
");
x=sc.nextInt();
System.out.print("\nEnter value of
'n':");
n=sc.nextInt();
}
public void display()
{
for(int i=0;i< =n;i=i+2)
{
sum=sum + fact(x+i)/(double)j;
}
System.out.println("\nSum of the series: "+sum);
}
public
int fact(int n)
{
int i,f=1;
for(i=1;i< =n;i++)
{
f=f*i;
}
return f;
}
public static void main(String args[])
{
Search ob=new Search();
ob.assign();
ob.display();
}
}
Back To BlueJ Series Display Programs Home Page: CLICK HERE
No comments:
Post a Comment