Radical Developers welcomes all the visitors to be a member of the team. Come join us. Its all about open-source concept. All Programs are written and tested in MacOS X, Unix, Linux and may not match with the outputs of Turbo C++ in Windows

Sunday, January 9, 2011

Write a program to add first seven terms of the following series using For-Loop : (1/1!)+(2/2!)+(3/3!)+…………


Source Code :

#include<stdio.h>
void main()
{
      int i,j,n;  //Declaration of variables
      long float fact=1,sum=0,div; //Declaration of variables
      clrscr();
      for(i=1;i<=7;i++) //For Loop for calculating Sum
      {
            fact=1;
            for(j=1;j<=i;j++)
            {
                  fact*=j;    //Calculation of Factorial
            }
            div=i/fact;
            sum+=div;  
      }
      printf("\nSum of First Seven Terms : %5.2f",sum);
      getch();
}

Output :

Sum of First Seven Terms : 2.72

No comments:

Post a Comment