Wednesday, 16 January 2013

Expansion of e^x

#include<stdio.h>

int main()
{
  float x,term,sum;
  int cnt,n;
  printf("\t\t\t Expansion and sum of e^x\n\n");
  printf("Enter the value of x= ");
  scanf("%f",&x);
  printf("Enter the Power of x= ");
  scanf("%d",&n);
  printf("\nExpansion of %0.0f^%d is= ",x,n);
  for(cnt=1,term=1,sum=0;cnt<=n;cnt++)
    {
      if(cnt==1)
        printf("1");
      else
       {    sum=sum+term;
        term=term*x/cnt;
        printf("+ (%0.0f^%d)/%d!",x,cnt-1,cnt-1);
       }
    }
  printf("\nSum of the series is= %0.3f",sum);
return 0;
}

No comments: