Linear Program: Problems
-
Given two positive numbers that denote sides $a$ and $b$ of a rectangle, write a program that prints the perimeter and the square. Example:
Input: a = 5, b = 7 Output: perimeter is 24, square is 35 -
Write a program that converts the speed in km/h to m/s. Example:
Input: 36 Output: 10 -
Write a program that converts the Celsius temperature to the Reamur, Kelvin and Fahrenheit temperatures using these formulas. \begin{align*} R &= 0.8 \cdot C \newline F &= 1.8 \cdot C + 32 \newline K &= 273.15 + C \
\end{align*} Example:Input: C = 37 Output: R = 29.6, F = 98.6, K = 310 -
Given coefficients $A$, $B$, and $C$ of a quadratic equation $Ax^2 + Bx + C = 0$, write a program that prints the equation solutions $x_1$ and $x_2$. Use the formula for solving the quadratic equation: \begin{align*} D &= B^2-4ac \newline x_1 &= \frac{-b + \sqrt{D}}{2a} \newline x_2 &= \frac{-b - \sqrt{D}}{2a} \end{align*} Example:
Input: A = 1, B = 3, C = -10 Output: x1 = 2, x2 = -5 -
Write a program that finds the maximum of two numbers. You can use the following formula: $max(a, b) = \frac{a + b + |a - b|}{2}$. Example:
Input: a = 5, b = 7 Output: 7Modify the program to calculate
- the minimum of two numbers $min(a, b)$;
- the maximum of three numbers $max(a, b, c)$;
- the minimum of three numbers $min(a, b, c)$.
-
Write a program that calculates the resistance $R$ of two resistors with the resistance $R_1$ and $R_2$ assuming that
- the resistors $R_1$ and $R_2$ are connected in series, i.e. $R = R_1 + R_2$;
- the resistors are connected in parallel, i.e. $\frac{1}{$} = \frac{1}{R_1} + \frac{1}{R_2}$.
Example:
Input: R1 = 4, R2 = 8 Output: 1) Resistance when connected in series is 12; resistance when connected in parallel is 2.67.