Why this code is not giving output?

Why this code is not giving output? When the input value of n>1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Example program
#include <iostream>
#include<cmath>
using namespace std;
int main()
{ 
int factorial(int);
double s=-2;int n,fact,x;
cout<<"Enter the no. of terms of series :";
cin>>n;
cout<<"Enter the value of x: ";
cin>>x;
for(int i=1;i<=n-1;n++)
{
   fact=factorial(i*2);
   if(i%2==0)
   {
       s=s-(pow(x,i)/fact);
   }
   else
   s=s+(pow(x,i)/fact);
}
cout<<"Sum ="<<s;
return 0;
}
int factorial(int n)
{
    int f=1;
    for(int i=1;i<=n;i++)
    {
        f=f*i;
    }
    return f;
}


       
   
Last edited on
What is it supposed to do?
Topic archived. No new replies allowed.