Tut1 2
Tut1 2
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
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
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.
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.