#include<stdio.h>
#include<conio.h>
#define ACCURACY 0.00001
main()
{
int count,n;
float x,term,sum;
clrscr();
printf("\n enter the value of x : ");
scanf("%f",&x);
n=term=sum=count=1;
while(n<100)
{
term=term*x/n;
sum=sum+term;
count=count+1;
if(term<ACCURACY)
n=200; // to get out of the loop if accuracy b/w terms is less than 0.00001
else
n=n+1;
}
printf("\n NO. of Terms=%d sum=%f",count,sum);
getch();
}
#include<conio.h>
#define ACCURACY 0.00001
main()
{
int count,n;
float x,term,sum;
clrscr();
printf("\n enter the value of x : ");
scanf("%f",&x);
n=term=sum=count=1;
while(n<100)
{
term=term*x/n;
sum=sum+term;
count=count+1;
if(term<ACCURACY)
n=200; // to get out of the loop if accuracy b/w terms is less than 0.00001
else
n=n+1;
}
printf("\n NO. of Terms=%d sum=%f",count,sum);
getch();
}
No comments:
Post a Comment