Skip to content

Commit

Permalink
add if-else, countdown and sum of evens
Browse files Browse the repository at this point in the history
  • Loading branch information
AlphonseMehounme committed Nov 30, 2024
1 parent 9df8e00 commit 93d62f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Rust/rustifinity/challenges/countdown.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pub fn countdown(n: u32) -> Vec<u32> {
// TODO: Implement the countdown using a while loop
if n == 0 {
vec![0]
} else {
let mut vect : Vec<u32> = Vec::new();
let mut m = n;
while m > 0 {
vect.push(m);
m -= 1;
}
vect.push(0);
vect
}
}
8 changes: 8 additions & 0 deletions Rust/rustifinity/challenges/if-else.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub fn is_even(n: i32) -> bool {
// Your code here...
if n % 2 == 0 {
true
} else {
false
}
}
9 changes: 9 additions & 0 deletions Rust/rustifinity/challenges/sum-of-even-numbers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pub fn sum_of_evens(start: i32, end: i32) -> i32 {
let mut sum = 0;
for num in start..=end + 1 {
if num % 2 == 0 {
sum += num;
}
}
sum
}

0 comments on commit 93d62f0

Please sign in to comment.