Error while calculating sum of n terms of a exponential series to n terms:

Following is my program for calculating the sum of exponential series upto n terms:

e = 1/0! + 1/1! + 1/2! + 1/3! + 1/4! + 1/5!+....1/n!

Code:

`#include<stdio.h>`

int main()

{

int n,i,p=1;

float sum=1.0,fact=1.0;

printf("enter the number of terms");

scanf("the number of terms are %d",&n);

for(i=1;i<=n;i++)

{

while(p<=i)

{

fact*=p;

p++;

}

sum+=(1.0/fact);

}

printf("the sum is %f",sum);

system("pause");

return 0;

}

While executing the code in dev-C++, the program stops executing and goes into an infinite loop after entering 'n'. Kindly help.