关于c语言大小写输出的问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 05:52:53
请大家帮忙,就是要做
输入小写出大写
输入大写出小写
而且还要用for,while,if,等函数
救命啊!
而且输入其他的还会出error

#include<stdio.h>
main()
{
char c;
printf("enter a char:");
c=getchar();
if(c>='A' && c<='Z')
printf("%c",c=c+32);
else
if(c>='a' && c<='z')
printf("%c",c=c-32);
else
printf("error!");
getch();
}

#include <stdio.h>
main()
{
char ch ;
ch=getchar();
if(ch>='A'&&ch<='Z') ch=(ch+32);

if(ch>='a'&&ch<='z') ch=(ch-32);

printf("%c",ch) ;

}

哎呀 还是你自己做吧! 这样对你有好处
告诉你思路吧! 用IF嵌套 判断是不是在A—Z, a-z
如果在A—Z,就把ASCII 加 20H (十进制是32) 如果在a-z 就减 20H
如果两个范围都不在 就输出 error