Skip to content
Snippets Groups Projects
Commit e45fb298 authored by Michaël El Kharroubi's avatar Michaël El Kharroubi :satellite:
Browse files

Merge branch 'rust_min' into 'main'

Adds a very early and naive code using basic types and control strcuture in Rust

See merge request orestis.malaspin/rust-101!2
parents f28421aa 07c9e7e5
No related branches found
No related tags found
No related merge requests found
target
Cargo.lock
[package]
name = "part00"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
/// Rust basics:
/// - basic types (usize, i32, str)
/// - const, let, let mut
/// - control structures (for, if)
/// - collection: arrays, indexing
/// - macros for IO and errors
// No functions, only types used are i32, usize and [i32; SIZE].
// Indexing of array, for and if else control structures.
// Macros: panic! for error handling, print! and println! for I/O.
// Clippy does not like the code at all.
fn main() {
const SIZE: usize = 9;
let tab: [i32; SIZE] = [10, 32, 12, 43, 52, 53, 83, 2, 9];
if SIZE == 0 {
panic!("Size is of tab = 0.");
}
println!("Among the numbers in the list:");
for i in 0..SIZE {
print!("{} ", tab[i]);
}
println!();
let mut min = tab[0];
for i in 1..SIZE {
if min > tab[i] {
min = tab[i];
}
}
println!("The minimal value is: {}", min);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment