C语言大小写程序请教

来源:百度知道 编辑:UC知道 时间:2024/05/01 12:44:20
#include <stdio.h>
main()
{
char c1;
c1=getchar();
printf("%c\n",c1);
c1=c1+32;
putchar(c1);
}

呵呵,这个程序是转换大小写的,大家帮忙看看问题出在那?
难道非得定义2个变量才能计算。
也请回答的朋友不要用IF语句,谢谢 !
呵呵,WXD11011 ,你说的我知道
但是我是在输入大写字母的情况下,他都无法运行。
我现在也不需要进行判断。
我希望你能指点下,这个程序在 我输入大写字母的情况下为什么会报错呢。

设计要求:转换字母,如果输入小写则输出大写,如果输入大写则输出小写

方法一:不使用库函数,程序如下:
//////////////////////////////////////////
#include <stdio.h>
#include <conio.h>
#include <assert.h>
main()
{
char c1;
c1=getchar();
assert(c1>=65&&c1<=90||c1>=97&&c1<=122);//确保输入的是字母
printf("%c\n",c1);
c1=c1>+65&&c1<=90?c1+32:c1-32;
putchar(c1);
getch();
}
//////////////////////////////////////////////

方法二:使用库函数,程序如下:
/////////////////////////////////////////////
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <assert.h>

main()
{
char c1;
c1=getchar();
assert(c1>=65&&c1<=90||c1>=97&&c1<=122);//确保输入的是字母
printf("%c\n",c1);
c1=islower(c1)?toupper(c1):tolower(c1);
//islower(c1)是判断是否为小写形式,toupper(c1)是转换为大写,tolower(c1)是转换为小写
putchar(c