美文网首页
2020-04-07

2020-04-07

作者: 于渤文 | 来源:发表于2020-04-07 16:39 被阅读0次

    学习了字符串数组,

    1.

    #include<stdio.h>

    #include<string.h>

    int main(){

    int i;

    char a[80]={"If so, you already have a Google Account. You can sign in on the right."};

    for(i=0;i<80;i++){

    if(a[i]>='A'&&a[i]<='Z'){

    a[i]+=32;

    }else if(a[i]>='a'&&a[i]<='z'){

    a[i]-=32;

    }

    }

    printf("转换后:%s",a);

    }

    2.

    #include<stdio.h>

    #include<string.h>

    int main(){

    int i;

    int n1;

    int n2;

    int n3;

    int n4;

    char a[255]={};

    printf("请输入一串字符:");

    scanf("%s",&a);

    int sum1=0;

    int sum2=0;

    int sum3=0;

    int sum4=0;

    for(i=0;i<255;i++){

    if(a[i]>='0'&&a[i]<='9'){

    sum1++;

    }else if(a[i]>='a'&&a[i]<='z'){

    sum2++;

    }else if(a[i]>='A'&&a[i]<='Z'){

    sum3++;

    }else{

    sum4++;

    }

    }

    printf("数字:%d",sum1);

    printf("小写字母:%d",sum2);

    printf("大写字母:%d",sum3);

    printf("其他:%d",sum4);

    }

    3.

    #include<stdio.h>

    #include<string.h>

    int main(){

    int i;

    char A;

    char B;

    char a[200]={"\0"};

    printf("请输入一串字符:");

    gets(a);

    printf("请输入转化字符:");

    scanf("%c %c",&A,&B);

    for(i=0;i<strlen(a);i++){

    if(a[i]==A){

    a[i]=B;

    }

    }

    printf("转换后:%s",a);

    }

    相关文章

      网友评论

          本文标题:2020-04-07

          本文链接:https://www.haomeiwen.com/subject/cfmnphtx.html