99. Check if the String Numeric or Alphabetic

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>
#include <stdint.h>
int n=0;
int a=0;

void classify_string(const char *str) {
    // Your logic here
    for(int i=0;i<sizeof(str)-2;i++)
        if(str[i]>64)
            a=1;
        else if(str[i]>48 & str[i]<59)
            n=1;
        else {a=1;n=1;}

    if(n & a) printf("MIXED");
    else if(a) printf("ALPHABETIC");
    else if(n) printf("NUMERIC");
}

int main() {
    char str[101];
    fgets(str, sizeof(str), stdin);

    // Remove newline
    uint8_t i = 0;
    while (str[i]) {
        if (str[i] == '\n') {
            str[i] = '\0';
            break;
        }
        i++;
    }

    classify_string(str);
    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote