The source code to check a given character is a whitespace character or not is given below. The given program is compiled and executed successfully.
// Rust program to check whether a given character
// is a whitespace character or not
fn main() {
let mut ch:char = ' ';
let mut ch1:char = 'B';
if ( (ch == ' ' ) ||
(ch == '\t') ||
(ch == '\n') ||
(ch == '\r')
)
{
println!("Variable ch contains whitespace character");
}
else
{
println!("Variable ch does not contain whitespace character");
}
if ( (ch1 == ' ' ) ||
(ch1 == '\t') ||
(ch1 == '\n') ||
(ch1 == '\r')
)
{
println!("Variable ch1 contains whitespace character");
}
else
{
println!("Variable ch1 does not contain whitespace character");
}
}
Output:
Variable ch contains whitespace character
Variable ch1 does not contain whitespace character
Explanation:
Here, we created two character variables ch and ch1 that are initialized with ' ' and 'B' respectively. Then we checked the given characters contains whitespace characters or not and printed the appropriate message.
Program/Source Code:
The source code to check a given character is a whitespace character or not is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created two character variables ch and ch1 that are initialized with ' ' and 'B' respectively. Then we checked the given characters contains whitespace characters or not and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer