diff --git a/src/trivial_demonstrations/palindrome.rs b/src/trivial_demonstrations/palindrome.rs new file mode 100644 index 0000000..e47f12c --- /dev/null +++ b/src/trivial_demonstrations/palindrome.rs @@ -0,0 +1,14 @@ +use std::io; +fn main(){ +//here we take input + let mut num=String::new(); + io::stdin().read_line(&mut num).expect(""); + //here we use len() to find length of string + let half_len = num.len()/2; + // here we use take() for taking a substring and eq for comparing + //here we check palindrome + if num.chars().take(half_len).eq(num.chars().rev().take(half_len)) + {println!("it is palindrome");} + else + { println!("it is not palindrome");} +}