C language implementation to determine whether the input data is letters

Problem Description

Enter a data to determine whether the data is a letter

operation result

method one

Insert image description here

Method Two

Insert image description here

Code

method one

#include <stdio.h>
#include <ctype.h>

int main() {
    
    
    char ch;
    
    printf("请输入一个字符:");
    scanf("%c", &ch);
    
    if (isalpha(ch)) {
    
    
        printf("输入的字符是字母。\n");
    } else {
    
    
        printf("输入的字符不是字母。\n");
    }
    
    return 0;
}

Method 2: (not perfect)

#include<stdio.h>
int main(){
    
    
	char word;
	scanf("%c",&word);
	if(word>='a' && word<='z' || word>='A'&& word<='Z'){
    
    
		printf("YES\n");
	}else{
    
    
		printf("No\n");
	}
	return 0;
} 

おすすめ

転載: blog.csdn.net/weixin_52312427/article/details/132964235