C语言,输入一串字符,将大写字母转换为小写字母输出 编一C语言程序,任意输入一个大写字母,将其转换成小写字母并输...
C\u8bed\u8a00 \u529f\u80fd\uff1a\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5c0f\u5199\u5b57\u6bcd\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u5927\u5199\u5b57\u6bcd\uff0c\u5176\u4ed6\u5b57\u7b26\u4e0d\u53d8\u6e90\u4ee3\u7801\u5982\u4e0b\uff1a
#include "stdio.h"
#include "conio.h"
char *toDaXie(char *s);/*\u51fd\u6570--\u53d8\u5927\u5199*/
main()
{
char *s;
printf("Input a string please!\n");
gets(s);
printf("The result:\n%s\n",toDaXie(s));
getch();
}
char *toDaXie(char *s)/*\u51fd\u6570--\u53d8\u5927\u5199\u7684\u5177\u4f53\u5185\u5bb9*/
{
int i;
for(i=0;i96&&s[i]<123)/*\u5982\u679c\u8fd9\u4e2a\u5b57\u662f\u5c0f\u5199\u5b57\u6bcd*/
s[i]-=32;/*\u90a3\u5c31\u628a\u5b83\u53d8\u6210\u5927\u5199*/
}
return s;}
\u6269\u5c55\u8d44\u6599
1\u3001\u5728C++\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0c\u7a0b\u5e8f\u5458\u9700\u8981\u4f7f\u7528 for() \u5faa\u73af\u8bed\u53e5\u65f6\uff0c\u5e38\u5e38\u5c06\u5faa\u73af\u904d\u5386\u5b9a\u4e49\u5728 for() \u5185\u90e8\u3002
2\u3001C\u8bed\u8a00\u7a0b\u5e8f\u7684\u201c\u77ed\u8def\u8868\u8fbe\u5f0f\u201d\u51b3\u5b9a\u4e86\u53ea\u6709 executeStepA() \u51fd\u6570\u6210\u529f\u624d\u4f1a\u63a5\u7740\u6267\u884c executeStepB() \u51fd\u6570\uff0c\u53ea\u6709 executeStepB() \u51fd\u6570\u4e5f\u6210\u529f\uff0c\u624d\u4f1a\u6267\u884c executeStepC() \u51fd\u6570\u3002
\u56e0\u4e3a\u662f\u5927\u5199\u5b57\u6bcd\u8f6c\u5316\u4e3a\u5c0f\u5199\u5b57\u6bcd\uff1b\u6211\u4eec\u53ef\u4ee5\u8003\u8651\u8fd0\u7528ASCII\u7801\u6765\u89e3\u51b3\u8fd9\u7c7b\u95ee\u9898\u3002\u6839\u636eASCII\u7801\uff0c\u5927\u5199\u5b57\u6bcd\u53d8\u4e3a\u5c0f\u5199\u5b57\u6bcd\u53ea\u9700\u8981+32\u5373\u53ef.
\u4f8b\u5982\u6211\u4eec\u5b9a\u4e49char ch1='B';\u6211\u4eec\u4ec5\u9700\u8981\u8f93\u51fach1+32\u5373\u53ef\uff1b
\u4e0b\u9762\u5199\u7ed9\u51fa\u5177\u4f53\u7a0b\u5e8f\uff1a
\u9996\u5148\u5b9a\u4e49\u4e00\u4e2a\u5b57\u7b26\u53d8\u91cf\uff1b\u7136\u540e\u63d0\u9192\u8f93\u5165\u5927\u5199\u5b57\u6bcd\uff1b\u5728\u8f93\u5165\u5927\u5199\u5b57\u6bcd\u540e\uff1b\u7531ASCII\u7801\u8f6c\u5316\u540e\uff1b\u8f93\u51fa\u7684\u5373\u4e3a\u5c0f\u5199\u5b57\u6bcd\u3002\u8fd9\u662f\u4e00\u79cd\u5f88\u7b80\u6d01\u7684\u8f6c\u5316\u65b9\u5f0f\u3002
\u5f53\u7136\uff1b\u8fd9\u79cd\u7a0b\u5e8f\u4e5f\u6709\u5f0a\u7aef\uff1b\u5f53\u4f60\u8f93\u5165\u5c0f\u5199\u5b57\u6bcd\u65f6\uff1bASCII\u7801\u5c31\u4f1a\u8d85\u51fa\u8303\u56f4\uff1b\u56e0\u4e3a\u6700\u9ad8\u4e3a127\uff1b\u800ca\u7684ASCII\u7801\u4e3a97\uff1b\u52a0\u4e0a32\u540e\u4e3a129\uff0c\u663e\u7136\u8d85\u51fa\u8303\u56f4\uff1b\u7a0b\u5e8f\u4f1a\u65e0\u5185\u5bb9\u8f93\u51fa\u3002
\u4e0d\u8fc7\uff0c\u89e3\u51b3\u5927\u5199\u5b57\u6bcd\u8f6c\u5316\u5c0f\u5199\u5b57\u6bcd\u5012\u662f\u7ef0\u7ef0\u6709\u4f59\u7684\u3002
\u6269\u5c55\u8d44\u6599ASCII\uff08American Standard Code for Information Interchange\uff0c\u7f8e\u56fd\u4fe1\u606f\u4ea4\u6362\u6807\u51c6\u4ee3\u7801\uff09\u662f\u57fa\u4e8e\u62c9\u4e01\u5b57\u6bcd\u7684\u4e00\u5957\u7535\u8111\u7f16\u7801\u7cfb\u7edf\uff0c\u4e3b\u8981\u7528\u4e8e\u663e\u793a\u73b0\u4ee3\u82f1\u8bed\u548c\u5176\u4ed6\u897f\u6b27\u8bed\u8a00\u3002\u5b83\u662f\u73b0\u4eca\u6700\u901a\u7528\u7684\u5355\u5b57\u8282\u7f16\u7801\u7cfb\u7edf\uff0c\u5e76\u7b49\u540c\u4e8e\u56fd\u9645\u6807\u51c6ISO/IEC 646\u3002
\u8bf7\u6ce8\u610f\uff0cASCII\u662fAmerican Standard Code for Information Interchange\u7f29\u5199\uff0c\u800c\u4e0d\u662fASC\u2161(\u7f57\u9a6c\u6570\u5b572)\uff0c\u6709\u5f88\u591a\u4eba\u5728\u8fd9\u4e2a\u5730\u65b9\u4ea7\u751f\u8bef\u89e3\u3002
\u4e0b\u6709\u5177\u4f53ASCII\u5bf9\u7167\u8868
\u767e\u5ea6\u767e\u79d1-ASCII
void main()
{
int i;
char s[100];
gets(s);//输入字符串
for (i=0;s[i]!='\0';i++)
if (s[i]>='A'&&s[i]<='Z')s[i]+=32;//将大写字母转换成小写
for (i--;i>=0;i--)printf("%c",s[i]);//逆序输出
printf("\n");//换行
}
另外,团IDC网上有许多产品团购,便宜有口碑
#include<stdio.h>
main()
{
int i=0;
char s[1000];
gets(s);
while(s[i])
{
if(s[i]>='A'&&s[i]<='Z')
s[i]=s[i]-'A'+'a';
i++;
}
puts(s);
}
代码如下:
#include <stdio.h>
#include <string.h>
#define buffer 1024
int main(void)
{
int i;
char a[buffer];
while(scanf("%s",a)!=EOF)
{
for(i=0;i<strlen(a);i++)
{
if(a[i]>='A'&&a[i]<='Z')
a[i]+=32;
}
printf("%s\n",a);
}
return 0;
}
注意:输入字符后回车,将把其中的大写字母(如果有)转换为小写字母,输入^z(windows系统)结束程序。
#include<stdio.h>
#include <string.h>
int main()
{
int i=0;
char a[1000];
while(scanf("%s",a)!=EOF)
{
for(i=0;i<strlen(a);i++)
{
if(a[i]>='A'&&a[i]<='Z')
a[i]=a[i]+32;
}
puts(a);
}
return 0;
}
绛旓細浠g爜濡備笅锛歩nclude<stdio.h> intmain(){ charx,y;printf("璇杈撳叆涓涓瀛楁瘝锛");scanf("%c",&x);if(x>='a'&&x<='z')y=x-32;if(x>='A'&&x<='Z')y=x+32;printf("杞崲鍚庣殑瀛楃涓猴細%c\n", y);} 浠g爜鍦―EVC++鐜涓嬭繍琛屾晥鏋滃涓嬶細...
绛旓細1銆杈撳叆瀛楃锛鍙互浣跨敤getchar鎴栬卻canf鐨%c鏍煎紡銆2銆佸湪ASCII鐮佽〃涓紝瀵瑰簲鐨勫皬鍐欏瓧姣嶆瘮澶у啓瀛楁瘝澶32锛屾墍浠ヨ緭鍑哄鍔32涔嬪悗鐨勫煎嵆鍙3銆佽緭鍑哄彲浠ヤ娇鐢╬utchar鎴栬卲rintf銆4銆佸弬鑰冧唬鐮侊細include <stdio.h>int main(){ char c; c=getchar();//杈撳叆銆 if(c>='A' && c<='Z')//鏄ぇ鍐欏瓧...
绛旓細include<stdio.h>void main() { char s[256],ss[256]; int i,n; gets(s); i=n=0; while ( s[i]!=0 ) { if ( s[i]>='A' && s[i]<='Z' ) { ss[n]=s[i]; n++; } i++; } ss[n]=0; printf("%s\n%d\n",ss,n);} ...
绛旓細int upper = 0; //瀹氫箟涓涓彉閲忥紝鐢ㄦ潵缁熻澶у啓瀛楁瘝鐨勪釜鏁 int lower = 0; //瀹氫箟涓涓彉閲忥紝鐢ㄦ潵缁熻灏忓啓瀛楁瘝鐨勪釜鏁 int i; //瀹氫箟涓涓惊鐜彉閲 printf("璇杈撳叆涓娈靛瓧绗涓诧細\n");scanf("%s", str); //浠庢爣鍑嗚緭鍏ヨ鍙栦竴涓瀛楃涓诧紝瀛樺叆str鏁扮粍 for (i = 0; i < strlen(str); i++...
绛旓細open \n");else printf("file opened for writing \n");char ch;while((ch = getchar()) != '\n'){ fputc(toupper(ch),fp);} fputc('#',fp);if(fclose(fp)!=0)printf("file cannot be closed \n");else printf("file is now closed \n");return 0;} 绋嬪簭杩愯濡備笅锛...
绛旓細include <stdio.h>int main(){ int n=0; char x[]="china"; for(n=0 ;x[n]!='\0' ;n++) { if(x[n]<='z'&&x[n]>='a') x[n]=x[n]-32; putchar(x[n]); } return 0;}
绛旓細include<stdio.h> main(){ char s[];int i=0;for(i=0;;i++)scanf("%c"*s[i]);for (i=0;s[i]!='/0';i++){ if(s[i]>='A'&&s[i]<='Z')s[i]+=32;/灏嗗ぇ鍐瀛楁瘝鏀逛负灏忓啓 else if(s[i]>='a'&&s[i]<='z')/灏嗗皬鍐欐敼涓哄ぇ鍐 s[i]-=32;} printf("%c",s[...
绛旓細include<stdio.h>#include<ctype.h>#include<string.h>void main(){ char a[100],*p,y;int x,i,num;gets(a);p=a;x=strlen(a);//涓嶇煡閬撲綘涓棿杩涓娈鏈夊暐鐢 鎴戝叏鍒犱簡for(i=0;i<x;i++)if(*(p+i)>=65&&*(p+i)<=90)printf("%c",*(p+i));}FONTNAME and FONTAMELFONT...
绛旓細鐢ㄦ寚閽堢紪鍐绋嬪簭 include<stdio.h> void main(){ char a[100];int sum0=0,suma=0,sumA=0;gets(a);char*p;for(p=a;*p!='\0';p++){ if(*p>='0'&&*p<='9')sum0+=1;else if(*p>='a'&&*p<='z')suma+=1;else if(*p>='A'&&*p<='Z')sumA+=1;} printf("鏁板瓧瀛楃鏁伴噺...
绛旓細include <stdio.h> include <conio.h> main(){ char str[100] = {0};printf( "input:\n" );scanf( "%s",str );int i = 0;if( str[0]>='a' && str[0]<='z' ) str[0]=str[0]-'a'+'A';while( str[i] != '\0' ){ if( str[i] == ' ' ){ if( str[i+1...