Posted by: Sourav | May 14, 2015

Sum of a series 1square/1 factorial+ 2square/2 factorial+..n in C


  #include<stdio.h>
#include<conio.h>
#include<math.h>
double fac(int);
void main()

{
int i,n;
double d,sum=0,j;
clrscr();
printf(“Enter the value of n\n”);
scanf(“%d”,&n);

printf(“You have entered n = %d\n”,n);
for(i=1;i<=n;i++)
{
d=fac(i);
printf(“The factorial of %d is %f\n”,i,d);
j=pow(i,i);
sum=sum+j/d;

}
printf(“The sum is %f”,sum);
getch();
}
double fac(int n)
{
double mul=1;
while(n>=1)
{
mul=mul*n;
//  printf(“The mul is %f\n”,mul);
n–;
}

return mul;
}

 

The sum of 1square/1factorial +2square/2factorial+…nsquare/nfactorial

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: