Hex digits return

PHOTO EMBED

Thu Jun 06 2024 06:57:47 GMT+0000 (Coordinated Universal Time)

Saved by @meanaspotato #c

#include <stdio.h>

int is_hex_digit(char input)
{
    if((input>='0'&&input<='9')||(input>='a'&&input<='z')||(input>='A'&&input<='F'))
    {
        return 1;
    }
    else
    {
        return 0;
    }
    
}

int main(void)
{
    char input;
    printf("> ");
    scanf(" %c",&input);
    
    int output = is_hex_digit(input);
    
    printf("%d",output);
    
    return 0;
}
content_copyCOPY

Objective: Develop a program that determines if a given character is one of the symbols used to represent a hexadecimal digit. Guidelines: Function Declaration & Definition: is_hex_digit Function: Input: A character. Output: An integer value (either 1 or 0). Logic: The function should determine if the input character is a valid hexadecimal digit: Hexadecimal digits range from '0' to '9' and 'A' to 'F' (considering both uppercase and lowercase for A to F). Return 1 if the character is a valid hexadecimal digit. Return 0 otherwise. Main Program Execution: Within the main function: Prompt the user to input a character. (The prompt itself may be unspecified and can be designed as needed.) Retrieve and store the user's input. Call the is_hex_digit function with the stored character. Print the returned integer value from the function (either 1 or 0).