The value of e^x is 1+x+(x^2)/2+(x^3/3) …… (x^n/n). We are taking values of x and n from user.
Below is the code for the above problem in C#:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("The value of e^x is 1+x+(x^2)/2+(x^3/3) ...... (x^n/n) ");
Console.WriteLine("Enter the value of x: ");
int x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the value of n: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Sum is: " + Exp(x,n));
Console.ReadLine();
}
static double Exp(int x, int n)
{
double sum = 1;
for (int j = 1; j <= n; j++)
{
sum = sum + (Math.Pow(x, j) / j);
}
return sum;
}
}
