#include <stdio.h>
#include <math.h>

int main()

    float i, x;
    double fact=0, sum=0;

    printf("Enter value of x as the power of e: ");
    scanf("%f", &x);

    printf("Enter n as the number of terms:  ");
    scanf("%d",&i);    

    for (i = 0; i < 99999; i++)

    {   
        sum = 1 + x;
        fact = fact * i;
        sum = sum + pow(x, i)/(fact);   
    }
    if (sum == sum)

    printf("The value of e^%f is %lf",x,sum);

    return 0;

Why are you asking for n then reading it into i? And why are you then just ignoring it in your loop control?

Here is the series solution and an alternative solution. In you can opt for any of both, solution #2 is more accurate, more concise and faster. I hope you can understand and tranlate the VB.Net code:

        Dim sum As Double = 0
        Dim fact As BigInteger = 1
        Dim esx As String = InputBox("x = ?")
        Dim x As Double = Double.Parse(esx)
        Dim x0 As Double = x
        Dim es As String = InputBox("n = ?")
        Dim n As Int32 = Int32.Parse(es)
        es = InputBox("solution 1/2")
        If es = "1" Then
            ' Solution #1 '
            sum = 1 + x
            For i As Int32 = 1 To n
                x *= x
                fact *= i + 1
                sum += x / CType(fact, Double)
            Next
        Else
            ' Solution #2 '
            ' exp(x) = lim(1+x/n)^n when n->Infinity  '
            sum = Math.Pow(1 + x / n, n)
        End If
        TextBox1.Text = sum.ToString + " " + Math.Exp(x0).ToString
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.