Problem 1. (1 point) The SolEc algorithm shown below is used with a = 0, b = 2 and n = 3. What is the value of c on the line Write c?
Function z <- f (x)
z = 85−99x + 15x2 − x3;
End Function
algorithm SolEc
Read a, b, n;
For i From 1 To n Do
c = (a + b) / 2;
Write a, ",", c, ",", b;
If f (a) * f (c) <0 Then
b = c;
If not
a = c;
End yes
End To Write c;
End Algorithm
c =
Here,
1)Function z <- f (x)
2)z = 85−99x + 15x2 − x3;
3)End Function
4)algorithm SolEc
5)Read a, b, n;
6)For i From 1 To n Do
7)c = (a + b) / 2;
8)Write a, ",", c, ",", b;
9)If f (a) * f (c) <0 Then
10)b = c;
11)If not
12)a = c;
13)End yes
14)End To Write c;
15)End Algorithm
In line 6) , The loop executes 3 times:
and final value of c= (0 + 2)/2 =1
Then program prints:
0,1,2
For , f(a) , programs goes to function call, with x=0; and returns 85 as f(a).
For , f(b) , programs goes to function call, with x=2; and returns 0 as f(b).
So f(a) * f(b) = 0 which is not less than 0.
So, else part of if statement gets executed. i.e. a=c = 1
So, The value of c on Line Write c is 1.
Hope you find this helpful.
Please provide an upvote , if you like the solution.
Get Answers For Free
Most questions answered within 1 hours.