[go: up one dir, main page]

0% found this document useful (0 votes)
13 views1 page

15) Iterative Structure - Exercise 7 - Part 1 of 3

The document presents Exercise 7 from Chapter 4 of an algorithm course, which involves writing algorithms to calculate specific mathematical expressions. It provides a detailed algorithm for calculating the sum S based on user inputs for n and x, ensuring both values are greater than zero. The algorithm iterates through a loop to compute the sum and outputs the final result S.

Uploaded by

soufiene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

15) Iterative Structure - Exercise 7 - Part 1 of 3

The document presents Exercise 7 from Chapter 4 of an algorithm course, which involves writing algorithms to calculate specific mathematical expressions. It provides a detailed algorithm for calculating the sum S based on user inputs for n and x, ensuring both values are greater than zero. The algorithm iterates through a loop to compute the sum and outputs the final result S.

Uploaded by

soufiene
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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 nx N
ix
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);
S0;
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

You might also like