Tuesday, January 26, 2010

Program To Find The Sum Of Series 1+1/2+1/3+...+1/n In Java?

class sum

{

public static void main(String args[]) 

{

int n,i,result=0;

System.out.println("Enter the limit n");

Scanner scanner=new Scanner(System.in);

int n=scanner.nextInt();

for(i=1;i<=n;i++) result=result+(1/n);

System.out.println("The result is "+result);
}

}