You are on page 1of 2

TP I1101 n2

Exercise 1
Write a C program that takes from the user an integer x, and displays on the screen its absolute
value.

Execution example:
Enter x: -5
The absolute value obtained = 5

Exercise 2
Write a C program that multiplies two integer numbers entered by the user and divides the result
by a third number also entered by the user, if it is not 0, then displays the result on the screen.

Execution example:
Enter three numbers A, B and C: 3 5 10
a * b / c = 3 * 5/10 = 1.5

Exercise 3
Write a C program that takes from the user 3 numerical values n1, n2 and n3 representing the
three notes of a student, calculates their arithmetic mean M and displays its grade on the
following criteria:
Failure, M < 10
Passable, 10 M < 12
Well 12 M < 14
Good 14 M < 16
Very Good 16 M < 18
Excellent M 18

Execution example:
Enter 3 notes n1, n2 and n3: 15.5 17 18.5
The average M of these notes is: 17
The grade of this student is: "very good"

Exercise 4
Write a C program that takes from the user 3 real values a, b and c and displays them on the
screen in ascending order.

Execution example:
Enter the 3 real values a, b and c: 15 4.3 13.2
The three real values will be shown on the screen as follows: 4.3 13.2 15
Exercise 5
Write a C program that takes from the user 3 characters c1, c2 and c3 and transforms each
character to a lowercase character if it was entered in upper case or to an uppercase character if it
was entered in lowercase. We must display on the screen the three characters after processing.

Execution example:
Enter 3 characters c1, c2 and c3: F b n
They will be displayed on the screen: f B N

Exercise 6 Two versions : if and switch


Write a C program that takes from the user the values of two integer variables A and B.
According to the value of A + B, the program calculates and displays the value of C. The
following table shows the calculation to be done according to (the) value (s ) of A + B (we will
use one time the if statement and then we use the switch)

If A + B = - 1 C=A+2
If A + B = 1 or 2 C=A*B2
If A + B = 3 or 4 C = 3 (B A)
For any other value of A and B C=A+B

Execution example:
Enter the value of A: 1
Enter the value of B: 2
C = 3 * (2-1) = 3

You might also like