harish reddy

harish reddy

  • NA
  • 162
  • 33.4k

Program output c sharp

Dec 18 2017 3:08 AM
Write a program in C# Sharp to find the sum of the series [ x - x^3 + x^5 + ......] using for loop. I did till here...but not getting the ouput.
 
int x = int.Parse(Console.ReadLine());
int n = int.Parse(Console.ReadLine());
double sum = 0;
for (int i = 1; i <= n; i=i+2)
{
double result = Math.Pow(x, i);
sum = sum + result;
}
Console.WriteLine(sum);
 

Answers (5)