Saturday, August 4, 2012

Series addition

Q. Write a C program to add the following series and print the result of addition:


(1/1!) + (2/2!) + (3/3!) + (4/4!) + (5/5!)


Ans.


/*c program to add the given series and print the result of its addition*/
#include<stdio.h>
#include<conio.h>
int main()
{
 float num,c,tmp,fact,res=0;
 for(num=1; num<=5; num++)
 {
  for(tmp=1, fact=1; tmp<=num; tmp++)
  {
    fact = fact*tmp;
    c = num/fact;
  }
  res=res+c;
 }
 printf("Result of series addition: \n");
 printf("\n(1/1!) + (2/2!) + (3/3!) + (4/4!) + (5/5!) = %f",res);
 getch();
 return 0;
}


/************Output************/
Output of add the specific given series C program
Screen shot for add the given series C program

No comments:

Post a Comment