class Test
{
public static void main(String[] args)
{
int n=4;
if(n%2==0)
System.out.println(Add(n));
else
System.out.println(Odd(n));
}
public static double Add(int n)
{
double sum=0;
for(int a=1;a<n/2+1;a++)
{
double b=1/(a*2);
sum=sum+b;
}
return sum;
}
public static double Odd(int n)
{
double sum=0;
for(int a=0;a<n/2;a++)
{
double b=1/(a*2+1);
sum=sum+b;
}
return sum;
}
}
|
|