Q:

Write a program in C# Sharp to find the sum of the series [ 1-X^2/2!+X^4/4!- .........]

0

Write a program in C# Sharp to find the sum of the series [ 1-X^2/2!+X^4/4!- .........]

Sample Output:

Calculate the sum of the series [ 1-X^2/2!+X^4/4!- .........]:                                                                                                 
----------------------------------------------------------------    
Input the Value of x :5                                                                                                                                        
Input the number of terms : 2                                                                                                         
the sum = -11.5                                                                                                         
Number of terms = 2  
value of x = 5

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;  
public class Exercise18 
{  
    public static void Main()
{
	double x,sum,t,d;
	int i,n;
	
	Console.Write("\n\n");
    Console.Write("Calculate the sum of the series [ 1-X^2/2!+X^4/4!- .........]:\n");
    Console.Write("----------------------------------------------------------------");
    Console.Write("\n\n");	
	
	Console.Write("Input the Value of x :");

    x= Convert.ToInt32(Console.ReadLine()); 	
	Console.Write("Input the number of terms : ");
    n= Convert.ToInt32(Console.ReadLine()); 	
	sum =1; t = 1;
	for (i=1;i<n;i++)
	{
	  d = (2*i)*(2*i-1);
	  t = -t*x*x/d;
	  sum =sum+ t;
	}
	Console.Write("\nthe sum = {0}\nNumber of terms = {1}\nvalue of x = {2}\n",sum,n,x);
 } 
} 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now