多语言展示
当前在线:832今日阅读:167今日分享:16

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

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

实现任意大小写字母转换。代码如下:#includevoid 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); }

2

小写字母转换成大写字母的代码如下:#includevoid main(){ char inputch,outputch; printf('please input one charater:'); scanf('%c',&inputch); outputch=inputch-32; printf('result:%c to %c\n',inputch,outputch);}

3

大写字母转换成小写字母的代码如下:#includevoid main(){ char inputch,outputch; printf('please input one charater:'); scanf('%c',&inputch); outputch=inputch+32; printf('result:%c to %c\n',inputch,outputch);}

4

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

推荐信息