判断char型变量c1是否为大写字母的最简单且正确的表达式为以下哪一个?编程证明

a) 'A' <= cl <= 'Z' b) (c1 >= A)&& (cl <= Z) c) A <= cl <= Z d) (c1 >= 'A') && (cl <= 'Z'),关键是要编程序证明这个选项,不明白怎么编程

第1个回答  2018-09-18
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define A 0
#define Z 0

#define ChoiceAmount 4

typedef bool (* choiceFunction_t)(const char);

static const char *upperString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const char *lowerString = "abcdefghijklmnopqrstuvwxyz";
static const char *choiceName = "ABCD";

static bool ChoiceA(const char cl);
static bool ChoiceB(const char cl);
static bool ChoiceC(const char cl);
static bool ChoiceD(const char cl);

int main(int argc, char *argv[])
{
    choiceFunction_t choiceArr[] = {ChoiceA, ChoiceB, ChoiceC, ChoiceD};
    bool isCorrect[] = {true, true, true, true};
    
    for(unsigned int functionIndex = 0; functionIndex < ChoiceAmount; functionIndex++)
        for(unsigned int letterIndex = 0; upperString[letterIndex] != '\0'; letterIndex++)
            if(!choiceArr[functionIndex](upperString[letterIndex]))
                isCorrect[functionIndex] = false;
    
    for(unsigned int functionIndex = 0; functionIndex < ChoiceAmount; functionIndex++)
        for(unsigned int letterIndex = 0; upperString[letterIndex] != '\0'; letterIndex++)
            if(choiceArr[functionIndex](lowerString[letterIndex]))
                isCorrect[functionIndex] = false;
    
    for(unsigned choiceIndex = 0; choiceIndex < ChoiceAmount; choiceIndex++)
        fprintf(stdout, "Choice%c is %s.\n", choiceName[choiceIndex], isCorrect[choiceIndex]?"correct":"incorrect");
    
    return EXIT_SUCCESS;
}

static bool ChoiceA(const char cl) { return 'A' <= cl <= 'Z'; }
static bool ChoiceB(const char cl) { return (cl >= A) && (cl <= Z); }
static bool ChoiceC(const char cl) { return A <= cl <= Z; }
static bool ChoiceD(const char cl) { return(cl >= 'A') && (cl <= 'Z'); }

第2个回答  2018-09-18
#include<stdio.h>
int main()
{
    char c1='D';
    if((c1 >= 'A') && (cl <= 'Z'))
    {
        printf("yes\n");
    }
    else
    {
        printf("no\n");
    }
    return 0;
}

本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网