SUMMATION OF EXPONENTIAL SERIES

/*  SUMMATION OF EXPONENTIAL SERIES  */

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
  {
    int x,n,i,prod;
    float t,sum;
    clrscr();
    printf("\n\t\tINPUT:");
    printf("\n\t\t------");
    printf("\n\t\tEnter the value for x:  ");
    scanf("%d",&x);
    printf("\n\t\tEnter the value for n:  ");
    scanf("%d",&n);
    printf("\n\t\tOUTPUT:");
    printf("\n\t\t-------");
    sum=1;
    t=1;
    for(i=1;i<=n;i++)
     {
       prod=i;
       t=t*x/prod;
       sum=sum+t;
     }
    printf("\n\t\tThe value for exp %d is:  %f",x,sum);
    printf("\n\t\tThe built-in value for given value is: 
                                              %f",exp(x));
    getch();
   }

INPUT:
------
Enter the value for x:  1
Enter the value for n:  5

OUTPUT:
-------
The value for exp 1 is:  2.716667
The built-in value for given value is:  2.718282

No comments:

Related Posts with Thumbnails