Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Day 2 assignment #6

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 61 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,74 @@
fn main() {
intro_to_u();
println!(
"Is Even? {}. The sum of the numbers, {} and {}.",
is_even(5, 5),
5,
5,
);
println!(
"Is Even? {}. The sum of the numbers, {} and {}.",
is_even(22, 21),
22,
21,
);
intro_to_f();
say_name("Eleazar", "Anonefdora");
}

// is sum even?
fn is_even(x: i32, y: i32) -> bool {
let z: i32 = sum_even(x, y);
if z % 2 == 0 {
true
} else {
false
}
}

fn sum_even(x: i32, y: i32) -> i32 {
x + y
}

// function to encapsulate all integers
fn intro_to_u() {
let sum_result: u8 = sum(5, 10);
println!("the sum result is: {}", sum_result);
// floating (arithmetic function)
fn intro_to_f() {
let sum_result: f32 = sum(5.02, 10.02);
println!("The sum is {:?}", sum_result);

let subtract: f32 = subtract(15.22, 10.02);
println!("The subtraction is {:?}", subtract);

let divide: f32 = divide(15.02, 10.41);
println!("The division is {:?}", divide);

let multiply: f32 = multiply(15.90, 10.02);
println!("The multiplication is {:?}", multiply);

let module: f32 = modulo(15.12, 10.02);
println!("The modulo is {:?}", module);
}

fn sum(x: u8, y: u8) -> u8 {
x + y // implicit return
// return x + y; // explicit return
fn sum(x: f32, y: f32) -> f32 {
x + y
}

fn subtract(x: f32, y: f32) -> f32 {
x - y
}

// subtract
// multiplication
// division
fn divide(x: f32, y: f32) -> f32 {
x / y
}

fn multiply(x: f32, y: f32) -> f32 {
x * y
}

fn modulo(x: f32, y: f32) -> f32 {
x % y
}

// String concatenation
fn say_name(first_name: &str, surname: &str) {
let full_name = format!("Hello, {} {}", first_name, surname);
println!("{}", full_name);
}