use std::io;
pub fn factorial (){
println!("Enter a positive integer 0 ~ 12 to get its factorial!");
let mut ent_input = String::new();
io::stdin().read_line(&mut ent_input).expect("Error while reading the input");
let mut input:u32 = match ent_input.trim().parse() {
Ok(input) => input,
Err(_input) => {
println!("A positive integer isn't entered, Please enter a positive integer!");
let mut errr:u32 = 1;
loop {
let mut ent_input1 = String::new();
io::stdin().read_line(&mut ent_input1).expect("Error while reading the input");
errr = match ent_input1.trim().parse() {
Ok(c) => {errr=c;
break;
},
Err(_errr) => {println!("A positive integer isn't entered, Please enter a positive integer!");
0},
};
};
errr
},
};
let referance = input; let mut result:u32 = input; if input == 0 {
result = 1;
}
else { while input>1{
let temp:u32=result; input=input-1;
result=input*temp;
}
}
println!("Factorial of {} is: {}",referance, result);
}