Here, we will create a character variable and check given character is a punctuation mark or not.
Program/Source Code:
The source code to check a given character is a punctuation mark or not is given below. The given program is compiled and executed successfully.
// Rust program to check a given character // is a punctuation mark or not fn main() { let ch:char = '#'; if ( 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!("character '{}' is a punctuation mark",ch); } else { println!("character '{}' is a punctuation mark", ch); } }
Output:
character '#' is a punctuation mark
Explanation:
Here, we created a character variable ch with the initial value of '#'. Then we checked the given character contains a punctuation mark or not and printed the appropriate message.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program/Source Code:
The source code to check a given character is a punctuation mark or not is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created a character variable ch with the initial value of '#'. Then we checked the given character contains a punctuation mark or not and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer