C Language Program To Find Sum Of Series


#include <stdio.h>
#include <conio.h>
long int factorial(int n);
void main()
{
 int n,i;
 float s,r;
 char c;
 clrscr();
 repeat : printf("\nYou have this series:- 1/1! + 2/2! + 3/3! + 4/4! ...");
 printf("\nTo which term you want its sum?  ");
 scanf("%d",&n);
 s=0;
 for (i=1;i<=n;i++)
  {   s=s+((float)i/(float)factorial(i)); }
 printf("\nThe sum of %d terms is %f",n,s);
 fflush(stdin);
 printf ("\nDo you want to continue?(y/n):-  ");
 scanf("%c",&c);
 if (c=='y')
  goto repeat;
 getch();
}

long int factorial(int n)
 {
  if (n<=1)
                return(1);
  else
                n=n*factorial(n-1);
                return(n);
 }

Sample Output :
     You have this series:- 1/1! + 2/2! + 3/3! + 4/4! ...
To which term you want its sum?  15
The sum of 15 terms is 2.709237
Do you want to continue?(y/n):-  n


Contact:
Mr. Roshan P. Helonde
Mobile: +91-7276355704
WhatsApp: +91-7276355704
Email: roshanphelonde@rediffmail.com
Share:

Total Pageviews

CONTACT US

Prof. Roshan P. Helonde
Mobile: +917276355704
WhatsApp: +917276355704
Email: roshanphelonde@rediffmail.com

Enter Project Title

Popular Projects

All Archive

Contact Form

Name

Email *

Message *