Skip to content

Latest commit

 

History

History
29 lines (19 loc) · 3.22 KB

S02-EN-conditional-control-structures.md

File metadata and controls

29 lines (19 loc) · 3.22 KB

Conditional Control Structures

  1. E01-palindrome-check: Create an algorithm that prints “Palindrome” if a 5-digit input number is a palindrome, or “Not a Palindrome” otherwise. A number is a palindrome if it reads the same forwards and backwards. Example: 545 is a palindrome number.

  2. E02-parking-fee: In a parking lot, the first hour (or fraction) costs $100 and each additional hour (or fraction) costs $80. Create an algorithm that takes as input the entry and exit times of a vehicle and calculates the amount to be paid.

  3. E03-interval-check: Given two values V1, V2 that form a closed interval, and a value X, create an algorithm to determine if X is inside or outside the interval.

  4. E04-bmi-calculator: The BMI (Body Mass Index) is an indicator of a person's weight in relation to their height. It is calculated by dividing the individual's mass (in kilograms) by the square of their height (in meters). Write an algorithm that, given a person's weight in pounds (1 pound = 0.453592 kg) and their height in centimeters, calculates their BMI and outputs their weight in kilograms, their BMI value, and the category in which they are classified.

    • Less than 16: Severe thinness.
    • 16 to 16.9: Moderate thinness.
    • 17 to 18.4: Mild thinness.
    • 18.5 to 24.9: Normal weight.
    • 25 to 29.9: Overweight.
    • 30 to 34.9: Obesity class I.
    • 35 to 39.9: Obesity class II.
    • 40 to 45: Obesity class III.
    • Greater than 45: Obesity class IV.
  5. E05-days-elapsed: Write an algorithm that takes as input a date (day and month) of the current year and prints the number of days elapsed since January 1st.

  6. E06-happy-number: A 4-digit number is happy if the first two digits are greater than the last two digits. For example, "5612" is happy because 56 is greater than 12. A 4-digit number is increasing if each digit is greater than the previous one. For example, "1569" is increasing because 9 > 6 > 5 > 1. Any number that is both happy and increasing is said to be a very happy number. Any number that is neither happy nor increasing is said to be unhappy. Create an algorithm that takes as input a 4-digit number and prints the type of number found, according to the described classification.

  7. E07-month-name: Create an algorithm that takes as input a number between 1 and 12 and prints the name of the corresponding month. Consider possible erroneous input values.

  8. E08-quadratic-roots:Write an algorithm that finds the values of a second-degree polynomial. It should receive the coefficients of the quadratic equation as input. The algorithm must print the roots of the quadratic equation, and if there is no real solution, it should indicate so.

  9. E09-coordinate-converter: Write an algorithm that converts polar coordinates to Cartesian coordinates and vice versa. The algorithm should take as input the desired type of conversion (from polar to Cartesian or from Cartesian to polar) and the corresponding coordinates. For the conversion from polar to Cartesian, the algorithm should take the radius (r) and the angle (θ) in degrees, and return the coordinates (x, y). For the conversion from Cartesian to polar, the algorithm should take the coordinates (x, y) and return the radius (r) and the angle (θ) in degrees.