0% found this document useful (0 votes)
9 views2 pages

Tut1 2

Uploaded by

abdolakamora2006
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)
9 views2 pages

Tut1 2

Uploaded by

abdolakamora2006
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/ 2

Badji Mokhtar Annaba university – Computer Science Department

Bachelor’s degree in Computer Science – 1st year - 2024 / 2025


Algorithms and Data Structures 1

Tutorial 1
Basic concepts (types, operations, algorithms)

Exercise 1:
a. What is the type of each variable: A=1, B=TRUE, test= 12.23, specialite = ’m’
b. Give examples of variables’ identifiers with their types, and possible values.

Exercise 2:
a. Given A=3, B=4, X=3.0, Y= -1.0

Specify the evaluation order as well as the value of each of the following expressions:
• X*A+Y
• B-A/Y+2

b. Given a = 4, b = 5, c = -1 et d = 0, evaluate the following logical expressions:


• (a < b) AND (c ≥ d)
• NOT (a < b) OR ( c ≠ b )

Exercise 3:
Trace the execution of the following algorithm

Algorithm Algo_01 ;
Var A, B, C : integer ;
D : boolean ;
begin
Read (A) ;
Read (B) ;
C ← A + B*2 + 3 ;
D ← (C mod A) < (C div B) ;
write (A,B,C,D) ;
End.

Exercise 4:
Consider the two following algorithms

Algorithm Algo_02 ; Algorithm Algo_03 ;


Var A : integer ; Var A : integer ;
Begin Begin
A  10 ; Read (A) ;
Write (A*A) ; Write (A*A) ;
Write (A*2) ; Write (A*2) ;
End. End.

a. What results does algorithm Algo_02 produce?


b. What results does algorithm Algo_03 produce?
c. What is the difference between them?

Pr. Halima BAHI


Badji Mokhtar Annaba university – Computer Science Department
Bachelor’s degree in Computer Science – 1st year - 2024 / 2025
Algorithms and Data Structures 1

Tutorial 2
Basic instructions (assign, read, write)

Exercise 1:
Consider the following algorithm:
Algorithm Algo_04 ;
Var A, B : integer ;
Begin
Read (A) ;
Read (B) ;
A←B;
B←A;
Write (A,B) ;
End.

a. Trace Algo_04 algorithm, introducing 5 and 10 as the values of A and B.


b. Do the instructions in the algorithm allow you to exchange the two values of B and A?
c. If the problem of exchanging the values of A and B is not solved, propose an algorithm
to solve this problem using an intermediate variable.

Exercise 2:
1. Write an algorithm that asks the user to enter a number, then it computes and displays
its double and its half.
2. Draw the flowchart corresponding to the previous question.
3. Write an algorithm that computes the distance between two points in two-dimensional
space.

Exercise 3:
Write the C program that converts a given number of seconds into hours, minutes, and seconds.

Exercise 4:
Consider again Exercise 1, and write the algorithm that allows swapping the two numbers A
and B without using an intermediate variable.

Pr. Halima BAHI

You might also like