问道关于C语言的小题!!

来源:百度知道 编辑:UC知道 时间:2024/05/05 12:04:29
从键盘输入一个任意的小写字母,转换为大写字母输出!!
这个怎么写!!!

我是这样写的 但是好象错了...
main()
{char a;
scanf("%c",&a);
printf("%c\n",a+32);}

该怎么改捏

main()
{char a;
scanf("%c",&a);
printf("%c\n",a-32);}

不算错误输入,这样改就行了。

上面的程序当你输入的是大写的话,会有其它字符输出的。

可以加上:

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

作判断。

#include<stdio.h>
main()
{
char c1,c2;
scanf("%c",&c1);
if(c1>='a'&&c1<='z')
c2=c1-32;
printf("%c\n",c2);
return 0;}

/* toupper()函数把小写字母转为大写,其他不变 */
/* scanf("%1s", &c)读入一个字符,跳过空白 */
#include <stdio.h>
#include <ctype.h>

main()
{
char c;
scanf("%1s", &c);
printf("%c\n", toupper(c));
}