#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{ clrscr();
int n,x,i,j;
float p,fact=1.0,sum=0.0;
cout<<"\n\tEnter the number: ";
cin>>n;
cout<<"\n\n\tEnter the Value of \'x\': ";
cin>>x;
for(i=1;i<=n;i++)
{ for(j=(2*j-1);j>0;j--)
{ fact=j*fact;
if(i%20==0)
p=(-1)*pow(x,(2*i-1));
else
p=pow(x,(2*i-1));
sum+=p/fact;
}
}
cout<<"\n\tThe sum is "<<sum;
getch();
}
Captain Neo
0
Newbie Poster
Recommended Answers
Jump to PostOne problem may be that you never initialized any of your variables.
//These could literally be any value. int n,x,i,j;
Here you create a variable 'j', and make a whole bunch of loop conditions that are based on 'j'... 'j' could be anything......
for([B]j[/B]=(2*[B]j[/B]-1);[B]j[/B]>0;[B]j[/B]--)
Jump to PostWell here is the code(Not edited) in code tag.
/*x-(x^3/3!)+(x^5/5!)-(x^7/7!).......*/ #include<iostream.h> #include<conio.h> #include<math.h> void main() { clrscr(); int n,x,i,j; float p,fact=1.0,sum=0.0; cout<<"\n\tEnter the number: "; cin>>n; cout<<"\n\n\tEnter the Value of \'x\': "; cin>>x; for(i=1;i<=n;i++) { for(j=(2*j-1);j>0;j--) { fact=j*fact; if(i%20==0) p=(-1)*pow(x,(2*i-1)); else p=pow(x,(2*i-1)); sum+=p/fact; } } cout<<"\n\tThe sum …
All 7 Replies
Clinton Portis
211
Practically a Posting Shark
richieking
44
Master Poster
PrimePackster
10
Runaway Poster
PrimePackster
10
Runaway Poster
VernonDozier
commented:
Pos. rep to to get you back in the game.
+15
richieking
44
Master Poster
PrimePackster
10
Runaway Poster
PrimePackster
10
Runaway Poster
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.