Algorithmic I Ch 4 : Iterative structure – 15) Exercise 7 - Part 1 of 3 2023/2024
Exercise 7 : (Course)
Write the algorithms that calculate the values of the following expressions :
a)
b)
c)
Solution :
1 x 2 x 3 x nx N
ix
a) F=1+ ... = 1+
1 x 2 x 2
3 x 3
n xn i 1 i xi
Algorithm exo7a;
Variable
i, n : integer; S, x : real;
Begin
/*We must read n with control: the minimum value of the final value (n) corresponds
to the initial value (i=1)*/
/*We must read x with control: according to the statement x must be > 0*/
Repeat
Print ("Give an integer n >0, and a real x>0 :");
Read(n, x);
Until (n>0 and x>0);
S0;
For i 1 to n do
S S + (i-x) / (i + x↑i);
EndFor;
S S +1; /*we add the value of the strange term to the sum*/
S 1; /*we initialize the sum by the value of the strange term*/
For i 1 to n do
S S + (i-x) / (i + x↑i);
EndFor;
Print("S=", S);
End
Page 1 sur 1