Finished lab_1 in Rust.

This commit is contained in:
Rhinemann 2023-05-07 09:26:25 +03:00
parent fe97b8dcde
commit 45ef70b268
2 changed files with 25 additions and 28 deletions

View File

@ -18,17 +18,12 @@ public class Lab_1 {
} }
public static void main(String[] args) { public static void main(String[] args) {
int n, m, a, b;
Scanner input = new Scanner(System.in); Scanner input = new Scanner(System.in);
n = protectedInput("n", input); final int n = protectedInput("n", input);
final int m = protectedInput("m", input);
m = protectedInput("m", input); final int a = protectedInput("a", input);
final int b = protectedInput("b", input);
a = protectedInput("a", input);
b = protectedInput("b", input);
input.close(); input.close();

View File

@ -1,20 +1,22 @@
fn main() { fn protected_read(variable_name: &str) -> i32 {
// use text_io::scan; use text_io::try_read;
use text_io::read; loop {
print!("Enter {}: ", variable_name);
print!("Enter m: "); let read_result: Result<i32, _> = try_read!();
let m: f32 = read!(); match read_result {
Ok(read_integer) => return read_integer,
print!("Enter n: "); Err(_e) => println!("{} must be an integer!", variable_name.to_uppercase()),
let n: f32 = read!(); }
}
print!("Enter a: "); }
let a: f32 = read!();
fn main() {
print!("Enter b: "); let n: i32 = protected_read("n");
let b: f32 = read!(); let m: i32 = protected_read("m");
let a: i32 = protected_read("a");
let s: f32 = ((b + m) / 2.0) * (m - b + 1.0) * (n - a + 1.0); let b: i32 = protected_read("b");
println!("S= {}", s); let s: f32 = ((b + m) as f32 / 2f32) * ((m - b + 1) * (n - a + 1)) as f32;
println!("S = {}", s);
} }