The source code to convert a given number of days into days, weeks, and years is given below. The given program is compiled and executed successfully.
// Rust program to convert a given number of days
// into days, weeks, and years
use std::io;
fn main() {
let mut ndays:i32 = 0;
let mut years:i32 = 0;
let mut weeks:i32 = 0;
let mut days:i32 = 0;
let mut input = String::new();
println!("Enter days: ");
io::stdin().read_line(&mut input).expect("Not a valid string");
ndays = input.trim().parse().expect("Not a valid number");
years = ndays / 365;
weeks = (ndays % 365) / 7;
days = (ndays % 365) % 7;
println!("{} years, {} weeks and {} days", years, weeks, days);
}
Output:
RUN 1:
Enter days:
471
1 years, 15 weeks and 1 days
RUN 2:
Enter days:
1008
2 years, 39 weeks and 5 days
Explanation:
Here, we read the total number of days from the user. Then we find the years, weeks, and days. After that, we printed the result.
Program/Source Code:
The source code to convert a given number of days into days, weeks, and years is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we read the total number of days from the user. Then we find the years, weeks, and days. After that, we printed the result.
need an explanation for this answer? contact us directly to get an explanation for this answer