In a class assignment, i have to write a cprogram to calculate the sum of the following series:
1/1!+3^2/2!+5^3/3!+......
for that i wrote the following program.
i added a few extra lines so that my series is also diplayed, but the problem is whenever i give the number of terms a s 18 or more, my compiler shows the following error,(at least similar to it
)
*img.photobucket.com/albums/v461/technomodel/untitled.jpg
but i need the sum of 50 terms
help plz guys, i'm in trouble, gotta submit it tomorrow. i use Turbo C++ 4.5 from Borland.
1/1!+3^2/2!+5^3/3!+......
for that i wrote the following program.
Code:
#include <stdio.h>
#include <math.h>
#include <ctype.h>
main()
{
float sum,term;
FILE *pt;
pt=fopen("series", "w+");
int count, tag, denom=1, num;
char answer='Y';
while (toupper(answer)=='Y')
{
printf("Enter the number of terms of the series : ");
fprintf(pt, "Enter the number of terms of the series : ");
scanf("%d", &count);
tag=count;
printf("The sum of the given series is\n");
fprintf(pt, "The sum of the given series is\n");
for (count=1;count<tag;count++)
{
sum=0;
denom=denom*count;
num=2*count-1;
term=pow(num,count)/denom;
sum=sum+term;
if(count==1 || count%7==0)
{
printf("\n(%d^%d)/%d! + ", num, count, count);
fprintf(pt, "\n(%d^%d)/%d! + ", num, count, count);
}
else {
printf("(%d^%d)/%d! + ", num, count, count);
fprintf(pt, "(%d^%d)/%d! + ", num, count, count);
}
}
count=tag;
denom=denom*count;
num=2*count-1;
term=pow(num,count)/denom;
printf("(%d^%d)/%d! = ", num, count, count);
fprintf(pt, "(%d^%d)/%d! = ", num, count, count);
sum=sum+term;
printf("%.2f", sum);
fprintf(pt, "%.2f", sum);
printf("\nDo you want to repeat the calculation with a different value of n?(Y/N) ");
fprintf(pt, "\nDo you want to repeat the calculation with a different value of n?(Y/N) ");
scanf("%s", &answer);
}
}
*img.photobucket.com/albums/v461/technomodel/untitled.jpg
but i need the sum of 50 terms
help plz guys, i'm in trouble, gotta submit it tomorrow. i use Turbo C++ 4.5 from Borland.