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

Tutorial N°1: Simple Sequential Algorithm: Exercise 01

Exercises

Uploaded by

chifaachott
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)
10 views2 pages

Tutorial N°1: Simple Sequential Algorithm: Exercise 01

Exercises

Uploaded by

chifaachott
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

University of Djilali BOUNAAMA Khemis Miliana Algorithms and Data Structures I

Faculty of Sciences and Technology 1st year CS


Department of Mathematics and Computer Science AZZOUZA N.

TUTORIAL N°1: SIMPLE SEQUENTIAL ALGORITHM

Exercise 01:

Indicate whether the following words can be used as identifier or values and give its type :
Xx25ab 2y -0.5 1,8 lire & '5' "vap" 'd" 0 'M' '#'
2
alpha 25,3 14.5 -11 c/n #ff a*b faux y g! "R"
Ajou5 +9 +10.6 "k=14.9" "15" vrai Ahmed gt-at Fi
xy<5 dy cinq google.com X_1 a1 "-11,6" 'vap' vap
1TD TD1 A800 89R Prénom Prix-HT Prix_HT
Code Postal Code_Postal CodePostal
Exercise 02:

Answer the following statements with “true” or “false” to (indicate errors):

1) Var S1, S2 : integer ; 2) Var S1, S2 : integer ; 3) Var S, S' : integer ;


4) Var A – B – C : integer ; 5) Var (A, B, C) : integer ; 6) Var A, B, c : integer ;
7) Var NomEtudiant : string; 8) Var nom étudiant: string; 9) Var nom_etudiant: string;
10) Var : R : real ; 11) Var R : float ; 12) Var R : real ; Var N : integer ;

Exercise 03:

Propose a declaration for each of the following variables:


 Student’ last name – Student number
 State of a switch – Roots of a 2nd degree equation
 Examination score – Status of a student
 Wilaya of Algeria – Number of available units of a product

Exercise 04: Given integer variables a, b, c, d and e, evaluate the following expressions:
a = 1, b = 2, c = 3, d = 4,
 a+b-c+d  a+d %b - c
 a * b/c+d  ++a * b - c--
 a * b MOD c  ++b / c + a * d++
a = 8,b =15,c = 4, a = 9,b =12,c = 3,
 2*((a MOD 5)*(4+(b-3)/( c+2)))  a- ((b/(3+c)) *2) -1
a = 11,b = 6,c = 0,d = 7,e = 5 a=1; b=2; c=4; d=6
 a+2 > b AND NOT c || a <> d AND a-2<=e  a+b/c*((d/3+4)/3+a)/b ;
 (a>b) OR NOT (c>=d) AND (b<c) ;

Exercise 05: The variables N, P and Q are integers and contain the values 5, 7 and 3 respectively. Are the
following expressions correct? If so, give their type and value.

– N mod P * Q
– N mod P div Q
– N = P ou N <= Q
– P div N < Q
1
Exercise 06 : Evaluate the following logical expressions with (a,b,c,d) = (2,3,5,10) and (X,Y) = (True, False)

1) (a  b)  (a  c) 2) ((a  b)  (a  c)) 3)  (a  b)  (a  c)
4) (a  b)  (c = d/2) 5) (d / a = c) = Y 6) (d / c = b) = Y
7) (d / c = b) = X 8) (a  b)  (d  c) 9) (a  b)  (d  c) = X

Exercise 07: Respond with “true” or “false” to each read or write operation (indicate errors):

1) Read (A) 2) Read (45) 3) Read (A+B)


4) Read ("A") 5) Read ("A = ", A) 6) Write (X + 2*Y)
7) Write ("A = ", A) 8) Write (A, " ", B) 9) Write (45)
10) Write (5 mod 7 div 2) 11) Write ("Give a number : ") 12) Write ("Root of " ,X," is ", SQRT(X))

Exercise 08 : What are the values of variables A, B, C in the following algorithms?:

Algorithm affecter1 Algorithm affecter2


Var A,B : integer ; Var A,B,C : integer ;
Begin Begin
A ← 1 ; A ← 6 ;
B ← A + 2 ; B ← 12 ;
A ← 3 ; C ← B+2 ;
End A ← A-2 ;
B ← C*2 ;
End
Algorithm affecter3 Algorithm concat
Var A,B,C : integer ; Var A,B,C : string;
Begin Begin
A ← 7 ; A ← "7" ;
B ← A+1 ; B ← A+ "a" ;
C ← B/2 ; C ← B+A ;
C ← C-2 ; End
A ← B ;
End

Exercise 09 : Write two C programs that SWAP or switches the values of two integer A and B: first using an
auxiliary variable and without an auxiliary variable for the second.
Exercise 10 : Write a C program that asks for a number from the user, then calculates and displays the square of
this number.
Exercise 11 : Write a C program that inputs the price of an item (excluding tax), the number of items and the
VAT rate. The program then provides the total price including tax. (Make sure the labels appear clearly)
Exercise 12 : Write a C program that allows you to calculate the determinant of a quadratic equation:
ax2 + bx + c.
Exercise 13 : Write a C program that calculates and displays the area of a rectangle, where the width and height
will be given by the user.

You might also like