Thursday, 28 June 2012

c++ program that calculate the sum of : 1!/1+2!/4+3!/9……..n terms.

#include<iostream.h>

int main()
{
int i,n,j,fa=1,sq;
float ans=0.0,sum=0.0;

cout<<"Enter any number : ";
    cin>>n;
for(i=1;i<=n;i++)
{
 


  for(j=1;j<=i;j++)
        fa=fa*j;

    sq=i*i;
    ans=(float)fa/(float)sq;
    sum+=ans;
    fa=1;
}

cout<<sum;

}