A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a program in C# Sharp to find the sum of the series [ x - x^3 + x^5 - x^7 + x^9 -.....]
Q:

Write a program in C# Sharp to find the sum of the series [ x - x^3 + x^5 - x^7 + x^9 -.....]

0

Write a program in C# Sharp to find the sum of the series [ x - x^3 + x^5 - x^7 + x^9 -.....]

Sample Output:

Calculate the sum of the series [ x - x^3 + x^5 - x^7 + x^9 - .....]:
------------------------------------------------------------

Input the value of x :Input number of terms : 
The sum = 410
Number of terms = 5
 The value of x = 2

All Answers

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

using System;  
public class Exercise24  
{  
public static void Main()
{
    double x,sum,ctr,p,term;
    int i,n;
    Console.Write("\n\n");
    Console.Write("Calculate the sum of the series [ x - x^3 + x^5 - x^7 + x^9 - .....]:\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());
    term=1;
	sum = 0;
	for (i=1,p=1;i<n+1;i++)
	{
	  ctr = Math.Pow(x, p);
	  sum = sum + ctr*term;
	  term=term*(-1);
	  p = p + 2;
	}
	Console.Write("\nThe sum = {0}\nNumber of terms = {1}\n The 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