WRITE A C PROGRAM TO FIND THE SUM OF THE FOLLOWING SERIES:
-1+(1/3!)-(1/5!)+(1/7!)-...n terms
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
float t=-1,s=0;
printf("Enter the number of terms you want to sum:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
s=s+t;
t=-t/((2*i+1)*(2*i));
}
printf("Series: %f",s);
getch();
}
Output:
Enter the number of terms you want to sum:2
Series: -0.833333
-1+(1/3!)-(1/5!)+(1/7!)-...n terms
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
float t=-1,s=0;
printf("Enter the number of terms you want to sum:");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
s=s+t;
t=-t/((2*i+1)*(2*i));
}
printf("Series: %f",s);
getch();
}
Output:
Enter the number of terms you want to sum:2
Series: -0.833333
Enter the number of terms you want to sum:Series: -nan
ReplyDeleteoutput is shown -nan