C programming problems

Algorithm and data structure

Sunday, December 21, 2014

Efficient Program to Compute Sum of Series 1/1! + 1/2! + 1/3! + 1/4! + .. + 1/n!


#include<stdio.h>
int main()
{
int fact[10];
int i,n;
float sum=0;
fact[1]=fact[0]=1;
printf("Enter value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact[i]=fact[i-1]*i;
sum+=(float)1/fact[i];
}
printf("%f",sum);
return 0;
}
Posted by Unknown at 12:05 PM
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Newer Post Older Post Home

About Me

Unknown
View my complete profile

Blog Archive

  • ►  2015 (4)
    • ►  February (4)
  • ▼  2014 (20)
    • ▼  December (20)
      • Print all possible combinations of r elements in a...
      • C++ program to print all distinct elements in a gi...
      • Efficient Program to Compute Sum of Series 1/1! + ...
      • Replace all ‘0’ with ‘5’ in an input Integer
      • "QQ.h" file for Queue Operation
      • "stack.h" file
      • Reverse of Queue using Stack
      • get_Minimum.h file
      • How to design a stack such that getMinimum() shoul...
      • var numposts = 100; var standardstyling = true...
      • Implement Queue Using Link List in c
      • Queue Operation in c
      • Queue Implemention Using Two Stacks in c
      • Sort a stack elements using recursion in c
      • Reverse the elements of stack using only stack ope...
      • program to check array of integers is palindrome o...
      • Stack Operation With Push() & Pop() Function
      • Implement Stack Using Array in C
      • Maximum SubArray sum in c++
      • remove duplicate elements from sorted link list in c
Travel theme. Powered by Blogger.