blob: fb682a654a375562731220d5e7186e6429f12d72 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
// Example 6.6
//Program to evaluate the series i.e.
// 1/1-x = 1+x+x^2+x^3+.....+x^n
x=input("Input value of x:"); //Read value of x
LOOP=100; ACCURACY=0.0001; //Initialization
sum1=0;term=1;flag=0;
//Computation using for loop
for n=1:LOOP
sum1=sum1+term;
if(term<=ACCURACY) then //Test for accuracy
flag=1;
break;
end
term=term*x;
end
//Print the results
if(flag==1) then
printf(" EXIT FROM LOOP\n");
printf(" Sum =%f ; No. of terms =%d",sum1,n);
else
disp("FINAL VALUE OF N IS NOT SUFFICIENT TO ACHIEVE DESIRED ACCURCY");
end
|