1/! 1 + 2/! 2 + 3/! 3 + …… solve this [ loop series ]

 




#include<stdio.h>
#include<conio.h>
#include<math.h>
 main()
 {

   float i,a,n,b,fact=1,sum=0;

   printf("enter the value of n :\n");
   scanf(" %f",&n);
   
   for(i=1;i<=n;i++)
   {
   fact*=i;
   a=i/fact;
   printf(" \n%f",a);
   sum=sum+a;

   }
   printf("\nyr value is %f",sum);


 }

output :
enter the value of n : 6 1.000000 1.000000 0.500000 0.166667 0.041667 0.008333 yr value is 2.716667

Comments

Popular Post

Write the definition for a class called complex that has floating point data members for storing real and imaginary parts. The class has the following member functions: void set(float, float) to set the specified value in object void disp() to display complex number object complex sum(complex) to sum two complex numbers & return complex number 1. Write the definitions for each of the above member functions. 2. Write main function to create three complex number objects. Set the value in two objects and call sum() to calculate sum and assign it in third object. Display all complex numbers.