Computer Science, asked by itsme51, 7 hours ago

Hii Guys ..Can you all please help me with this Java Program??

1/2! + 3/4! + 5/6! ..n terms...​

Answers

Answered by iamkhawarabbas78
1

Answer:

#import java.io.*

public int factorial(int n)

{

if(n==1)

return 1

else

return n*factorial(n-1)

}

public void main()throws IOException

{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in))

System.out.println("Enter n:")

int no=Integer.parseInt(br.readLine())

int sum=0

for(int i=1,i<=n,i++)

{

ifac=factorial(i)

sum=(i%2==0)?(sum-ifac):(sum+ifac)

}

System.out.println(sum)

}

Similar questions