Q:

Rust program to check whether a given character is a printable character or not

belongs to collection: Rust Basic Programs

0

Here, we will create a character variable and check given character is a printable character or not.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to check a given character is a printable character or not is given below. The given program is compiled and executed successfully.

// Rust program to check a given character 
// is a printable character or not

fn main() {
    let ch:char = '#';
    
    if ((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '!' || ch == '"' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' || ch == '*' || ch == '+' || ch == ',' || ch == '-' || ch == '.' || ch == '/' || ch == ':' || ch == ';' || ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' || ch == '[' || ch == '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}')
    {
       println!("Given character is printable character");
    }
    else
    {
       println!("Given character is not a printable character");
    }
}

Output:

Given character is printable character

Explanation:

Here, we created a character variable ch with the initial value of '#'. Then we checked the given character contains a printable character or not and printed the appropriate message.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to convert a given number of days int... >>
<< Rust program to check whether a given character is...