如何用C语言编写“从键盘上输入一个小写字母,将其本身及对应的大写字母输出”的程序?

如题所述

程序如下:

#include <stdio.h>

int main()

{

char ch;

scanf("%c",&ch);

printf("%c",ch-'a'+'A');

return(0);

}

示例一:

#include<stdio.h>

int main()

{

char ch;

scanf("%c",&ch);

printf("Letter %c converted into a letter %c!",ch,ch-32);//大写字母ASCII码比小写字母小32

return 0;

}

示例二:

ch=getchar();

if(ch>='a'&&ch<='z')

{ch=ch-32;

prinft("大写字母是:%c\n",ch);

}

else(printf("请输入大写字母");

)

示例三:

#include <stdio.h>

main()

{

char c;                         //声明变量

scanf("%c",&c);                //键盘上取值

printf("%c %c",c,ch-'a'+'A');//本身和大写输出

}

温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

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