您的位置首页百科知识

C语言学习:任意大小写字母转换

C语言学习:任意大小写字母转换

的有关信息介绍如下:

C语言学习:任意大小写字母转换

初学C语言的朋友,可能不会编写大小写字母转换的代码,现在就由我分享给大家。希望对大家有所帮助。

实现任意大小写字母转换。代码如下:

#include

void main()

{

char x='a';

printf("请您输入任意大写字母或者小写字母x:\n");

scanf("%c",&x);

if( x>='A' && x<='Z')

{

x=x+32;

}

else

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

{

x=x-32;

}

printf("%c\n",x);

}

小写字母转换成大写字母的代码如下:

#include

void main()

{

char inputch,outputch;

printf("please input one charater:");

scanf("%c",&inputch);

outputch=inputch-32;

printf("result:%c to %c\n",inputch,outputch);

}

大写字母转换成小写字母的代码如下:

#include

void main()

{

char inputch,outputch;

printf("please input one charater:");

scanf("%c",&inputch);

outputch=inputch+32;

printf("result:%c to %c\n",inputch,outputch);

}

最后,希望我的讲解对你有所帮助,觉得不错的话,请在大拇指图标处点击赞一下,谢谢你的支持!