0% found this document useful (0 votes)
59 views5 pages

2-Laboratory Work - Homework

Uploaded by

AVS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views5 pages

2-Laboratory Work - Homework

Uploaded by

AVS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

2- Laboratory work

You have a total of 18 assignments. You need to complete all the assignments before
the next lesson. All these assignments are graded with a maximum of 10 points.

1. Two integers are given. The program must output one if the first number is greater
than the second, two if the second is greater than the first, or zero if they are equal.
Input:
1
2
Output: 2

2. Write a program that takes three numbers from the user and prints the largest of
them.

Input: Three integers: 4 7 2

Output: The largest number among the three: The largest number is 7

3. Write a program that takes a year as input and determines if it is a leap year. A leap
year is divisible by 4, but not by 100 unless it is also divisible by 400.

Input: An integer representing the year: 2024

Output: 2024 is a leap year.

4. Three natural numbers A, B, C are given. Determine whether there exists a triangle
with these sides. If the triangle exists, print the YES line, otherwise print the NO line.

A triangle is three points that do not lie on the same line.

Input:
3
4
5
Output:
YES

5. Three integers are given. Determine how many of them match. The program must
output one of the numbers: 3 (if all numbers match), 2 (if two numbers match) or 0 (if
all numbers are different).

Input:
1
2
3
Output: 0
6. Design a program that calculates the price of a movie ticket based on age. The
prices are as follows:

 Children (0-12): $5
 Teenagers (13-19): $8
 Adults (20-64): $12
 Seniors (65+): $7

The program should also handle invalid ages (e.g., negative values).

Input: 15
Output:Ticket price: 8$

7. Create a program that determines the number of days in a given month of a given
year. Handle leap years correctly for February. Use the switch statement.
Input: 2 2024
Output: Number of days: 29

8. Write a program that converts an amount from one currency to another. Assume
the following conversion rates:

 USD to EUR: 0.93


 USD to GBP: 0.78
 USD to JPY: 134.47

The user should enter the amount in USD and choose the target currency.

Input: 100 E

Output: Amount in EUR: 93

9. Write a program that takes a number between 0 and 100 as input and prints a grade
based on the following scale:

 A (90-100)
 B (80-89)
 C (70-79)
 D (60-69)
 F (0-59)

Input: A number between 0 and 100: 85

Output: The corresponding letter grade: Grade: B

10. Write a program that takes a number between 1 and 7 and prints the corresponding
day of the week (1 — Monday, 2 — Tuesday, etc.) using the switch statement.

Input: A number from 1 to 7 :3

Output: The corresponding day of the week : Wednesday


11. Write a program that performs basic arithmetic operations (addition, subtraction,
multiplication, division) based on user input. Use the switch statement to select the
operation.

Input: An operator (+, -, *, /) and two numbers: * 5 3

Output: Result: 15

12. A chess rook moves horizontally or vertically. Given two different squares on the
chessboard, determine whether the rook can move from the first square to the second
square in one move.
Input data format: The program receives as input four numbers from 1 to 8 each,
specifying the column number and row number first for the first cell, then for the
second cell.
Output Data Format: The program should output YES if it is possible to get from the
first cell to the second cell with a rook move or NO otherwise.
Input:
4
4
5
5
Output:
NO

13. A chess king moves horizontally, vertically and diagonally, but only 1 square.
Given two different squares on a chessboard, determine whether the king can move
from the first square to the second square in one move.
Input data format: The program receives as input four numbers from 1 to 8 each,
specifying the column number and row number first for the first cell, then for the
second cell.
Output Data Format: The program should output YES if it is possible to get from the
first cell to the second cell with a king move, or NO otherwise.
Input:
4
4
5
5
Output: YES
14. A chess queen moves diagonally, horizontally or vertically. Given two different
squares on a chessboard, determine whether the queen can move from the first square
to the second square in one move.
Input data format: The program receives as input four numbers from 1 to 8 each,
specifying the column number and row number first for the first cell, then for the
second cell.
Output format: The program should output YES if it is possible to get from the first
square by a queen move to the second square or NO otherwise.
Input 1:
1
1
2
2
Output 1: YES
Input 2:
1
1
2
3
Output 2: NO

15. A chess knight moves with the letter “G” - two squares vertically in any direction
and one square horizontally, or vice versa. Given two different squares on a
chessboard, determine whether the knight can move from the first square to the
second in one move.
Input data format: The program receives as input four numbers from 1 to 8 each,
specifying the column number and row number first for the first cell, then for the
second cell.
Output Data Format: The program should output YES if it is possible to move a
knight from the first cell to the second cell, or NO otherwise.
Input 1:
1
1
1
4
Output 1: NO
Input 2:
1
1
8
8
Output 2: NO
16. A chocolate is a rectangle divided into N×M pieces. The chocolate bar can be
broken once in a straight line into two pieces. Determine whether it is possible to
break exactly K pieces from the chocolate bar in this way.
Input data format: The program receives three numbers as input: N, M, K
Output data format: The program should output one of two words: YES or NO
Input 1:
4
2
6
Output 1: YES
Input 2:
2
10
7
Output 2: NO

17. Yasha was swimming in a pool of size N×M meters and got tired. At this moment
he found that he is X meters away from one of the long boards (not necessarily the
nearest one) and Y meters away from one of the short boards. What is the minimum
distance Yasha must swim to get out of the pool and onto the edge?
Input data format: The program receives the numbers N, M, X, Y as input.
Output data format: The program should output the number of meters that Yasha
needs to swim to the board.
Input:
23
52
8
43
Output:
8
18. Three numbers are given. Arrange them in non-decreasing order.
Input:
1
2
1
Output: 1 1 2

You might also like