// 8. Program to find e to the power x using n terms of the exponential series.
#include<stdio.h>
#include<conio.h>
#include<math.h>
//Correction is required
void main()
{
int i,n,j;
float x,t, exp , sum=0;
clrscr();
printf("Enter the value for x:");
scanf("%f", &x);
printf("\nEnter the value for n:");
scanf("%d", &n);
if(n<=1)
{
printf("1\n");
getch();
exit(0);
}
printf("\nThe exponential series is:\n");
for(i=1;i<n;i++)
{
if(i==1)
printf("%d + ",i);
t=i;
for(j=i;j>1;j--)
{
t=t*(j-1);
}
exp=pow(x,i)/t;
sum=sum+exp;
printf("%.3f + ",exp);
}
printf("\nThe Exponential Value = %f",sum+1);
getch();
}
#include<stdio.h>
#include<conio.h>
#include<math.h>
//Correction is required
void main()
{
int i,n,j;
float x,t, exp , sum=0;
clrscr();
printf("Enter the value for x:");
scanf("%f", &x);
printf("\nEnter the value for n:");
scanf("%d", &n);
if(n<=1)
{
printf("1\n");
getch();
exit(0);
}
printf("\nThe exponential series is:\n");
for(i=1;i<n;i++)
{
if(i==1)
printf("%d + ",i);
t=i;
for(j=i;j>1;j--)
{
t=t*(j-1);
}
exp=pow(x,i)/t;
sum=sum+exp;
printf("%.3f + ",exp);
}
printf("\nThe Exponential Value = %f",sum+1);
getch();
}
No comments :
Post a Comment