import java.io.*;
class Typeconversion
{
public static void main(String args[])
{
double i;
float sum1=0.0f,sum=0.0f;
for(i=1;i<=20;i++)
{
sum1=(float)i;
sum+=(1/sum1);
}
i--;
System.out.println("I = "+i+"numbers");
System.out.println("Sum of (1/I) = "+sum);
}
}
Output
I = 20.0numbers
Sum of (1/I) = 3.5977397
class Typeconversion
{
public static void main(String args[])
{
double i;
float sum1=0.0f,sum=0.0f;
for(i=1;i<=20;i++)
{
sum1=(float)i;
sum+=(1/sum1);
}
i--;
System.out.println("I = "+i+"numbers");
System.out.println("Sum of (1/I) = "+sum);
}
}
Output
I = 20.0numbers
Sum of (1/I) = 3.5977397
No comments:
Post a Comment