How to resolve the algorithm Last Friday of each month step by step in the Rust programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Last Friday of each month step by step in the Rust programming language
Table of Contents
Problem Statement
Write a program or a script that returns the date of the last Fridays of each month of a given year. The year may be given through any simple input method in your language (command line, std in, etc).
Example of an expected output:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Last Friday of each month step by step in the Rust programming language
Source code in the rust programming language
use std::env::args;
use time::{Date, Duration};
fn main() {
let year = args().nth(1).unwrap().parse::<i32>().unwrap();
(1..=12)
.map(|month| Date::try_from_ymd(year + month / 12, ((month % 12) + 1) as u8, 1))
.filter_map(|date| date.ok())
.for_each(|date| {
let days_back =
Duration::days(((date.weekday().number_from_sunday() as i64) % 7) + 1);
println!("{}", date - days_back);
});
}
You may also check:How to resolve the algorithm Sum of elements below main diagonal of matrix step by step in the Java programming language
You may also check:How to resolve the algorithm Infinity step by step in the OxygenBasic programming language
You may also check:How to resolve the algorithm Loops/Downward for step by step in the Oberon-2 programming language
You may also check:How to resolve the algorithm Morse code step by step in the FutureBasic programming language
You may also check:How to resolve the algorithm Pentagram step by step in the jq programming language