5. Labs and Tasks
{0.2}
Task 1:
To do: A distance L in centimeters is entered. Use the operation of integer division to convert it to meters of (1 meter = 100 centimeters). Use comments to make the program clear to user. Give the log of your program in the form of a comment after the program code.
Expected output:
Please enter the distance in centimeters >>> 245 The distance in meters is 2
[Program name: L2task01.pas]
{0.2}
Task 2:
To do: A mass in kilograms is entered. Use integer division to convert it to tons (1 ton = 1000 kilos). Use comments to make the program understandable to user. Give the log of your program as a comment after the program code.
Expected output:
Please enter the mass in kilos >>> 4527 The mass in tons is 4
[Program name: L2task02.pas]
{0.3}
Task 3:
To do: The person's age in months is entered. Convert it to a person's age in years (e.g: 65 months is 5 full years, 24 months is 2 years). Verify the correctness of your program, give the log as a comment.
Expected output:
Please enter the age in months >>> 37 The age in years is 3
[Program name: L2task03.pas]
{0.3}
Task 4:
To do: A two-digit integer is entered. Output its first and second digits separated by commas (i.e. left and right digits).
Note: Run the program and enter a non-two-digit number. What has happened? Is the result correct? Later we will learn how to perform validation of the input data.
Expected output:
Please enter a two digit number >>> 37 The first and second are 7, 3 +++ Please enter a two digit number: >>> -35 The first and second are 5, 3 +++ Please enter a two digit number: >>> 90 The first and second are 0, 9
[Program name: L2task04.pas]
{0.3}
Task 5:
To do: A two-digit integer is entered. Output the addition and multiplication of its digits. Check the correctness of your program.
Note: Each digit of the number will be needed twice: in the calculation of the sum — the first time and in the calculation of the multiplication — the second time. It is recommended to use auxiliary variables for storing the values of the digits.
Expected output:
please enter a two digit number >>> 73 you entered 73. The result is 10, 21
[Program name: L2task05.pas]
{0.3}
Task 6:
To do: A three-digit integer is entered. Output all of its digits (the order does not matter). Check the correctness of your program, give the log in the form of a comment.
Expected output:
Please enter a three-digit number >>> -105 The three digits are : 1, 0, 5
[Program name: L2task06.pas]
{0.3}
Task 7:
To do: A three-digit integer is entered. Output the addition of its digits. Make sure that your program works correctly with negative numbers.
Expected output:
Please enter a three-digit number >>> -745 You entered: 745. The addition of its three digits is equal to 16
[Program name: L2task07.pas]
{0.4}
Task 8:
To do: Two digits (in the range from 0 to 9) are entered. Use the standard form of a number to make a number, the digits of which are the specified digits.
Expected output:
Please enter two digits >>> 3 >>> 5 The new number is 35 Check the following: 3, 5 => 35 7, 0 => 70 0, 4 => 4
[Program name: L2task08.pas]
{0.4}
Task 9:
To do: A two-digit integer is entered. Swap the values of its left and right digits and output the resulting number. Check the correctness of your program, give the log in the form of a comment.
Expected output:
please enter a two digit number >>> -57 you entered -57. The result is -75 Check the following: 35 => 53 -10 => -1
[Program name: L2task09.pas]
{0.4}
Task 10:
To do: A three-digit integer is entered. Swap the values of its left and middle digits. Check the correctness of your program, give the log in the form of a comment.
Expected output:
please enter a three digit integer >>> 846 After swapping the left and middle digits, the result is 486
[Program name: L2task10.pas]
{0.4}
Task 11:
To do: A three-digit integer is entered. Make a cyclic shift of digits to the left.
Expected output:
please enter a three digit integer >>> -734 After making a cyclic shift of digits to the left, the result is -347 Check the following: 123 => 231 -602 => -26
[Program name: L2task11.pas]
{0.4}
Task 12:
To do: A three-digit integer is known. Make a cyclic shift of digits to the right.
Expected output:
please enter a three digit integer >>> -184 After a cyclic shift of digits to the right, the result is -418
[Program name: L2task12.pas]
Tasks for self-solving
Note: tasks should be saved in a file with the name of the task, and be sure to insert a comment with the statement of the task in the code.
INTEGER
Integer7.
A two-digit integer is given. Find the sum and the product of its digits.
Expected output:
<< 47 results: sum = 11 product = 28
Integer9.
A three-digit integer is given. Using one operator of integer division find first digit of the given integer (a hundreds digit).
Expected output:
<< 188 results: 1
Integer10.
A three-digit integer is given. Output its last digit (a ones digit) and then its middle digit (a tens digit).
Expected output:
<< 916 results: ones 6, tens 1
Integer11.
A three-digit integer is given. Find the sum and the product of its digits.
Expected output:
<< 363 results: sum 12, product 54
Integer12.
A three-digit integer is given. Output an integer obtained from the given one by reading it from right to left.
Expected output:
<< 263 results: 362
Integer13.
A three-digit integer is given. Output an integer obtained from the given one by moving its left digit to the right side.
Expected output:
<< 124 results: 241