All submissions

Check if the String Numeric or Alphabetic

Code

#include <stdio.h>
#include <stdint.h>

int lenght(const char *str){
    int i = 0;
    while(*(str + i) != '\0'){
        i++;
    }
    return i;
}

void classify_string(const char *str) {
    // Your logic here
    int i = 0;
    int alpha = 0;
    int numeric = 0;
    int n = lenght(str);
    while(*(str + i) != '\0'){
        char c = *(str + i);
        if(c >= '0' && c <= '9'){
             numeric++;
        }

        else if((c >= 'A' && c <= 'Z')|| 
           (c >= 'a' && c <= 'z')){
             alpha++;
        }
        i++;
    }
    if(numeric == n){
        printf("NUMERIC");
    }
    else if(alpha == n){
        printf("ALPHABETIC");
    }
    else{
        printf("MIXED");
    }
}

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

 

 

 

Loading...

Input

123456

Expected Output

NUMERIC