lab1 ex2

You cannot submit for this problem because the homework's deadline is due.

Ex2_1. Basic geometry

Get a radius \(r\) from user input, and print the surface area and the volume (on separate lines) of a ball with radius r. Suppose r>0.

Sample Test Cases

Input:

3.2

Output:

  128.6796

  137.2583

Ex2_2. Sum of digits

Get a natural number from user input, and print the sum of all its digits. Suppose the user input is always a natural number \(n\in \N \cap[0,1000)\).

Hint 1: Consider how you perform number base conversion, and search the MATLAB documentation for floor() and mod().

Sample Test Cases

Input:

233

Output:

     8

Ex2_3. Quadratic equation solver

Get three real numbers \(a\), \(b\), and \(c\) from user input as a vector of length 3, and solve the equation \(a x^2 + b x + c = 0, a\neq 0\). Print its two solutions on separate lines.

In the case of two real roots, print the smaller one first. In the case of two complex roots, print the one with the smaller imaginary part first. In the case of two equal roots, print it twice.

Hint: Try sqrt(-1).

Sample Test Case

Input:

[1 2 3]

Output:

  -1.0000 - 1.4142i

  -1.0000 + 1.4142i

Lab 1 exercises

Not Claimed
Status
Finished
Problems
3
Open Since
2023-05-17 18:15
DDL
2023-05-18 00:00
Extension
48.0 hour(s)