1/1! + 1/2! + 1/3! +...............+ 1/n!

// 1/1! + 1/2! + 1/3! +...............+ 1/n!
Program:

#include<stdio.h>
int main()
{
int n,i,j,fact=1;
float sum=0;
printf("Enter n: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
sum=sum+(1.0/fact);
}
printf("sum= %f",sum);
return 0;
}

Output:



No comments:

Post a Comment

x^y using recursion

Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...