5
Reply

Program output c sharp

harish reddy

harish reddy

Dec 18 2017 3:08 AM
169
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);
 

Upload Source Code  Select only zip and rar file.
Answers (5)