Control Flow
Control Flow
Control Flow
The pricing policy of a travel agency for a group tour is given as follow:
- Group of 10 or more pax: 500$/pax.
- Group of less than 10 pax: 600$/pax.
Write a program to compute the total cost for a team to buy the tour. The program works as
below:
- Input a positive integer corresponding to the number of guest in the team.
- Calculate the total cost based on the above pricing policy.
- Print the result to screen console.
Input:
A positive integer corresponding to the numbẻr of passenger in the team.
Output:
A number showing the total cost.
Example:
Input Output
20 10000
Exercise 2
Write a program to compute the area of a rectangle. The program works as follows:
- Input two numbers corresponding to the height and the width of a rectangle.
- Compute the area of that rectangle.
- Print the result to screen console.
Input:
Two real numbers on a single line corresponding to height and base, separated by a space
character. Each number may have both integral and fractional parts.
Output:
A real number printed to screen console with minimum numbers of digits, while keeping exactly
2 digits in the fractional part of the result.
Example:
Input Output
45 10.00
Exercise 3
Write a program to enter 5 integers from the keyboard. Print the number of integers that have
values between 20 and 100. If there is no integer satisfies the above condition, print 0.
Example:
Input Output
1 21 25 33 200 3
Input: A line of 5 values separated by spaces
Output:Number of integers satisfy the condition
Exercise 4
Write a program that converts a positive integer entered from the keyboard to its 8-bit binary
representation. If the entered number is invalid or cannot be represented as an 8-bit binary
number, display the message "Unsuccessful!"
Input Output
15 00001111