0% found this document useful (0 votes)
33 views

CEF207 Tutorial1

The document contains 14 exercises for a Programming I tutorial on writing C programs. The exercises include writing programs to calculate area and perimeter of shapes, convert between units like Celsius to Fahrenheit, find factors of numbers, and manipulate arrays. The programs test basic programming concepts like input, output, arithmetic operations, conditional statements, and loops. The last exercise asks students to write a program to determine if a number is a "perfect number" based on the sum of its divisors.

Uploaded by

romarictibab45
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)
33 views

CEF207 Tutorial1

The document contains 14 exercises for a Programming I tutorial on writing C programs. The exercises include writing programs to calculate area and perimeter of shapes, convert between units like Celsius to Fahrenheit, find factors of numbers, and manipulate arrays. The programs test basic programming concepts like input, output, arithmetic operations, conditional statements, and loops. The last exercise asks students to write a program to determine if a number is a "perfect number" based on the sum of its divisors.

Uploaded by

romarictibab45
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/ 4

Faculty of Engineering and technologies / computer engineering/ school year 2021-2022

CEF 207: PROGRAMMING I


Tutorial sheet 1:
Exercise 1:

• Write a C program to enter length and breadth of a rectangle and find its area.
• Write a C program to enter radius of a circle and find its diameter, circumference and
area.
• Write a C program to enter length in centimetre and convert it into meter and
kilometre.
• Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
• Write a C program to enter temperature in Fahrenheit and convert to Celsius
• Write a C program to convert days into years, weeks and days
• Write a C program to find power of any number x ^ y.
• Write a C program to enter any number and calculate its square root.
• Write a C program to enter two angles of a triangle and find the third angle.
• Write a C program to enter base and height of a triangle and find its area.
• Write a C program to calculate area of an equilateral triangle
• Write a C program that take an integer as input compute it factorial and display the
result
• Write a C program to enter length and breadth of a rectangle and find its perimeter.
• Write a C program that take an integer and tell if it is a prime number or not

Exercise 2:

Write a C program to print a block F using hash (#), where the F has a height of six characters
and width of five and four characters. And also, to print a big 'C'.
Expected Output:
######
#
#
#####
#
#
#

Proposed by Dr SOP DEFFO Lionel L. 1


Faculty of Engineering and technologies / computer engineering/ school year 2021-2022

Exercise 3:

Write a C program to print the following characters in a reverse way.


Test Characters: 'X', 'M', 'L'
Expected Output: The reverse of XML is LMX

Exercise 4:
Write a C program to calculate the distance between the two points.
Test Data :Input x1: 25 Input y1: 15
Input x2: 35
Input y2: 10
Expected Output:
Distance between the said points: 11.1803

Exercise 5:

Write a C program to convert a given integer (in seconds) to hours, minutes and seconds.
Test Data :
Input seconds: 25300
Expected Output:
There are:
H:M:S - 7:1:40

Exercise 6:

Write a C program that accepts 4 integers p, q, r, s from the user where r and s are positive
and p is even. If q is greater than r and s is greater than p and if the sum of r and s is greater
than the sum of p and q print "Correct values", otherwise print "Wrong values".

Test Data :
Input the second integer: 35
Input the third integer: 15
Input the fourth integer: 46
Expected Output:
Wrong values

Exercise 7:

• Write a C program that read 15 numbers and sum of all odd values between them.
• Write a C program that prints all even numbers between 1 and 50 (inclusive)
• Write a C program that read 45 numbers and sum of all even values between them

Exercise 8:

Proposed by Dr SOP DEFFO Lionel L. 2


Faculty of Engineering and technologies / computer engineering/ school year 2021-2022

Write a C program to read the coordinates(x, y) (in Cartesian system) and find the quadrant to
which it belongs (Quadrant -I, Quadrant -II, Quadrant -III, Quadrant -IV).
Note: A Cartesian coordinate system is a coordinate system that specifies each point uniquely
in a plane by a pair of numerical coordinates. These are often numbered from 1st to 4th and
denoted by Roman numerals: I (where the signs of the (x,y) coordinates are I(+,+), II (−,+), III
(−,−), and IV (+,−). Test Data : Input the Coordinate(x,y)

Exercise 9:

Write a C program that reads an integer between 1 and 12 and print the month of the year in
English.

Exercise 10:

Write a C program to read and print the elements of an array of length 5, before print, put the
triple of the previous position starting from the second position of the array.
For example, if the first number is 2, the array numbers must be 2, 6, 18, 54 and 162

Test Data:
Input the first number of the array: 5
Expected Output:
n[0] = 5
n[1] = 15
n[2] = 45
n[3] = 135
n[4] = 405

Exercise 11:

Write a C program to read an array of length 6, change the first element by the last, the second
element by the fifth and the third element by the fourth. Print the elements of the modified
array.

Test Data:
Input the 5 members of the array:
15
20
25
30
35
Expected Output:
array_n[0] = 35
array_n[1] = 30
array_n[2] = 25
array_n[3] = 20
array_n[4] = 15

Proposed by Dr SOP DEFFO Lionel L. 3


Faculty of Engineering and technologies / computer engineering/ school year 2021-2022

Exercise 12:

Write a C program that accepts integers from the user until a zero or a negative number,
display the number of positive values, the minimum value, the maximum value and the
average of all numbers.
Input a positive integer:
Input next positive integer: 15
Input next positive integer: 25
Input next positive integer: 37
Input next positive integer: 43
Number of positive values entered is 4
Maximum value entered is 43
Minimum value entered is 15
Average value is 30.0000

Exercise 13:
Write a C program to print a binomial coefficient table.
Mx 0 1 2 3 4 5 6 7 8 9 10
----------------------------------------------------------
01
111
2121
31331
414641
5 1 5 10 10 5 1
6 1 6 15 20 15 6 1
7 1 7 21 35 35 21 7 1
8 1 8 28 56 70 56 28 8 1
9 1 9 36 84 126 126 84 36 9 1
10 1 10 45 120 210 252 210 120 45 10 1

Exercise 14:
Write a C program that telll if a number is perfect or not. A perfect number is a positive
number which sum of all positive divisors excluding that number is equal to that number. For
example, 6 is perfect number since divisor of 6 are 1, 2 and 3.
Sum of its divisor is 1 + 2+ 3 =6
Note: 6 is the smallest perfect number.
Next perfect number is 28 since 1+ 2 + 4 + 7 + 14 = 28

Proposed by Dr SOP DEFFO Lionel L. 4

You might also like