Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

UNIVERSITY OF CONSTANTINE 1 - CAMPUS

CHAAB ERSAS
G 1 YEAR COMMON CORE - ST
ST

Computer Science II

Lab #10 : Sub-algorithms


(Functions)
Part I : Directed Studies

Exercise N°01

Transform the procedure divisible(n, d, r) from exercise number 03 of the previous series
into a function with the same name.

Exercise N°02

Write a procedure that requests a number between 100 and 999 until the response is
satisfactory. In case of a response greater than 999, display the message: « Smaller ! » and
vice versa, « Greater ! » if the number is less than 100.

Exercise N°03

Write a function cubic (n) that determines whether a three-digit integer is cubic or not, and
that calls the pow(x, e) function, which returns the result of x to the power of e. A three-digit
number is considered cubic if it is equal to the sum of the cubes of its three digits.
Example: 153 is cubic because 153 = 1³ + 5³ + 3³.

Part II : Practical Work

Write a C program that asks the user for a positive integer x composed of three digits and
then informs whether this number is cubic or not, using the previous subprograms.

Execute the program by providing:

1) x = 21 : ……….…………………………………….……………………………
2) x = 089 : ……….…………………………………….……………………………
3) x = 135 : ……….…………………………………….……………………………
4) x = 153 : ……….…………………………………….……………………………
5) x = 257 : ……….…………………………………….……………………………
6) x = 370 : ……….…………………………………….……………………………
7) x = 371 : ……….…………………………………….……………………………
8) x = 372 : ……….…………………………………….……………………………
9) x = 399 : ……….…………………………………….……………………………
10) x = 0407: ……….…………………………………….……………………………
11) x = 0555: ……….…………………………………….……………………………
12) x = 1123: ……….…………………………………….…….……………………

You might also like