Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab 01

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Subject: PRO192

LAB 01
Mỗi Program tạo 1 project riêng có tên theo quy định sau:
Tên Project: <MASV>_ProgramXX
Ví dụ: Sinh viên có masv: CE123456. Tên Project được đặt tên như sau:

CE123456_Program01
CE123456_Program02
CE123456_Program03
CE123456_Program04
CE123456_Program05
…..

Nén tất cả bài làm lại với tên: submit.zip (hoặc submit.rar)

Sau đó submit bài làm (submit.zip hoặc submit.rar) vào mục Labs/Lab01/TênLớp
trên trang:
https://drive.google.com/drive/folders/1X5sMrAAfCOU-
EV5NTZcgxtUJAOtueLne?usp=sharing

Deadline: 17/01/2024, 09:00

Yêu cầu:
- Comment giải thuật đầy đủ
- Format code
- Thông tin phần author

Contents: 08 programs

Program 1 ( 1 marks)

Write the program that allows the user to enter the three edges (a, b and c) of the triangle
then calculates the perimeter and area of the triangle. The program must check that the
three input numbers can make a triangle or not.
Hint: use the function double sqrt (double n) of the math.h library to calculate the square root
of the parameter n.
Example 1: Please enter the first edge of triangle: -9
Please enter the second edge of triangle: 7
Please enter the third edge of triangle: 5
These three numbers must be a positive number!
Example 2: Please enter the first edge of triangle: 4
Please enter the second edge of triangle: -9
Please enter the third edge of triangle: 0
These three numbers must be a positive number!
Example 3: Please enter the first edge of triangle: 1
Please enter the second edge of triangle: 2
Please enter the third edge of triangle: 10 These
three numbers do not make a triangle!
Example 4: Please enter the first edge of triangle: 4
Please enter the second edge of triangle: 5
Please enter the third edge of triangle: 6
The perimeter of the triangle is 15
The area of the triangle is 9.921567

Program 2 ( 1 marks)

Write a program that allows the user to enter the height (h) and the base's radius (r) of the
cylinder and then calculates the total surface area and volume of the cylinder. The
program must check whether the height and the radius is a positive number or not.

Note: The value of π is 3.14159265358979323846 (use the constant M_PI of the math.h
library)
Example 1: Please enter the base's radius of the cylinder: -2
Please enter the height of the cylinder: 0
The height and radius of cylinder must be a positive number!
Example 2: Please enter the base's radius of the cylinder: 1
Please enter the height of the cylinder: 2
The total surface area of the cylinder is 18.8495559215
The volume of the cylinder is 6.2831853072

Program 3 ( 1 marks)

Write a program that allows the user to enter dividend called a and divisor called b. The
program must check whether a is a multiple of b or not.

Example 1: Please enter dividend: 23 Please


enter divisor : 7
23 is not a multiple of 7
Example 2: Please enter dividend: 100
Please enter divisor : 20
100 is a multiple of 20
Example 3: Please enter dividend: 57
Please enter divisor : 0
The divisor can't be zero!

Program 4 ( 1 marks)

Write a program that allows the user to enter two integers called a and b. The program
must solves linear equation "A*X + B = 0".
Example 1: SOLVING LINEAR EQUATION A*X + B = 0 PROGRAM:
------------------------------------------

Please enter the coefficients A: 0

Please enter the coefficients B: 0

Every value for X is a solution to the linear equation 0*X + 0 = 0


Example 2: SOLVING LINEAR EQUATION A*X + B = 0 PROGRAM:

------------------------------------------

Please enter the coefficients A: 0

Please enter the coefficients B: 9

There is no solution for the linear equation 0*X + 9 = 0

Example 3: SOLVING LINEAR EQUATION A*X + B = 0 PROGRAM:

------------------------------------------

Please enter the coefficients A: -2

Please enter the coefficients B: 5

The linear equation -2*X + 5 = 0 has an unique root is X = 2.50

Example 4: SOLVING LINEAR EQUATION A*X + B = 0 PROGRAM:

------------------------------------------

Please enter the coefficients A: 10

Please enter the coefficients B: 6

The linear equation 10*X + 6 = 0 has an unique root is X = -0.60

Program 5 ( 1 marks)

Write a program that calculates the sum S = 1 - 2 + 3 - 4 + ... + (-1 N+1 * N) and presents
the result as the example below.

Example 1: Please enter positive integer N: -7 Accept


positive number only!
Example 2: Please enter positive integer N: 1 The
sum is S = 1
Example 3: Please enter positive integer N: 11
The sum is S = 1 - 2 + 3 - 4 + 5 - 6 + 7 – 8 + 9 – 10 + 11 = 6

Program 6 ( 1 marks)

Write a program that calculates the sum:


And presents the result as the example below.
Example 1: Please enter positive integer N: 0 Accept
positive number only!

Example 2: Please enter positive integer N: 1

The sum is S = 1

Example 3: Please enter positive integer N: 5

The sum is S = 1!/2^0 + 2!/2^1 + 3!/2^2 + 4!/2^3 + 5!/2^4 = 14.00

Program 7 ( 1 marks)

Write a program that calculates the factorial N! = 1 * 2 * 3 * ... * N and presents the
result as the example below

Example 1: Please enter positive integer N: -7 N


must be greater than or equal 0!
Example 2: Please enter positive integer N: 0 Result:
0! = 1
Example 3: Please enter positive integer N: 9
Result: 9! = 1*2*3*4*5*6*7*8*9 = 362880!
Example 4: Please enter positive integer N: 20
Result: 20! =
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20 =
2432902008176640000

Program 8 ( 3 marks)

Write a program that allows users to enter a numeric array with N elements. The program
performs the functions:
1. The entered array is:

2. The reverse array is:

3. The minimum value of the numeric array is


4. The maximum value of the numeric array is

5. All the prime numbers in the array is/are


Example 1: How many element of numeric array? 0

The number of element of numeric array must be greater than 0!

Example 2: How many element of numeric array? 10

Please enter value for 10 elements:

Value of the 1st element is: 19

Value of the 2nd element is: 28

Value of the 3rd element is: 3

Value of the 4th element is: 482

Value of the 5th element is: 12

Value of the 6th element is: 5

Value of the 7th element is: 41

Value of the 8th element is: 156

Value of the 9th element is: 300

Value of the 10th element is: 184

*********************************

1. The entered array is: 19, 28, 3, 482, 12, 5, 41, 156, 300, 184

2. The reverse array is: 184, 300, 156, 41, 5, 12, 482, 3, 28, 19

3. The minimum value of the numeric array is 3

4. The maximum value of the numeric array is 478

5. All the prime numbers in the array is/are 19 3 5 41

END

You might also like