Q:

Write a program in C# Sharp to display the sum of the series [ 1+x+x^2/2!+x^3/3!+....]

0

Write a program in C# Sharp to display the sum of the series [ 1+x+x^2/2!+x^3/3!+....]

Sample Output:

Calculate the sum of the series [ 1+x+x^2/2!+x^3/3!+....]:                                                                                                     
------------------------------------------------------------                                                                                                   
Input the value of x :5                                                                                                         
Input number of terms : 5                                                                                                         
The sum  is : 65.375                                                                                                         
Number of terms = 5                                                                                                         
The 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 Exercise23  
{  
    public static void Main()
{
	double x,sum,no_row;
	int i,n;
	
	Console.Write("\n\n");
    Console.Write("Calculate the sum of the series [ 1+x+x^2/2!+x^3/3!+....]:\n");
    Console.Write("------------------------------------------------------------");
    Console.Write("\n\n");  	
	
	Console.Write("Input the value of x :");
    x= Convert.ToInt32(Console.ReadLine());  	
	Console.Write("Input number of terms : ");
	n= Convert.ToInt32(Console.ReadLine());  
	sum =1; no_row = 1;
	for (i=1;i<n;i++)
	{
	  no_row = no_row*x/(float)i;
	  sum =sum+ no_row;
	}
	Console.Write("\nThe sum  is : {0}\nNumber of terms = {1}\nThe value 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