判断char型变量c1是否为大写字母的最简单且正确的表达式为以下哪一个?编程证明
a)'A'<=cl<='Z'b)(c1>=A)&&(cl<=Z)c)A<=cl<=Zd)(c1>='A')&&(cl<='Z'),关键是要编程序证明这个选项,不明白怎么编...
a) 'A' <= cl <= 'Z' b) (c1 >= A)&& (cl <= Z) c) A <= cl <= Z d) (c1 >= 'A') && (cl <= 'Z'),关键是要编程序证明这个选项,不明白怎么编程
展开
2个回答
展开全部
#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'); }
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询