Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write function bool IsOddDigit( char ch ); that takes a character and returns tr

ID: 645165 • Letter: W

Question

Write function bool IsOddDigit( char ch ); that takes a character and returns true if the character is one of the odd digits { '1', '3', '5', '7', '9' }, otherwise return false. So the main() will call IsOddDigit() with various characters, and uses the return value from IsOddDigit() to decide to print one of two messages, that the character is an odd digit or that the character is not an odd digit.

The function IsOddDigit() may neither print nor accept input.  

Test with at least all the digits '0' through '9', the letters 'a', 'b' and 'c' (both lower and upper case), and several other characters such as punctuation marks and other special characters. You may use any method you want to generate characters to send to IsOddDigit(). You do not have to prompt for the characters.

Explanation / Answer

#include <stdio.h>

typedef int bool;
enum { false, true };
bool IsOddDigit( char ch ) {
//returns true if the character is one of the odd digits { '1', '3', '5', '7', '9' }, otherwise return false
if(ch == '1' || ch == '3' || ch == '5' || ch =='7' || ch =='9')
   return true;
else
    return false;
}

int main()
{
    printf("Hello, World! ");
bool r = IsOddDigit('1');
printf("%d",r)
;    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote