简单C语言应用

来源:互联网 发布:网络女歌手及歌曲 编辑:程序博客网 时间:2024/05/17 03:57
#include <stdio.h>
#include <string.h>
void main()
{
char a[100];
int i=0,t=0;
printf("请输入一个长度不超过100的字符串:");
scanf("%s",a);
//求出字符串的长度 
t=strlen(a);
printf("大小写转换后:"); 
for(i=0;i<t;i++)
{
//如果是小写字母,则转换成大写。 
if(a[i]>='a'&&a[i]<='z')
{
printf("%c",a[i]-32);
}
//如果是大写字母,则转换成小写。 
else if(a[i]>='A'&&a[i]<='Z')
{
printf("%c",a[i]+32);
}
//既不是大写,也不是小写,则原样输出。 
else
{
printf("%c",a[i]);
}
}
printf("\n");
0 0