• c语言 9-10


    1、

    #include <stdio.h>
    
    void del_dit(char x[])
    {
        int i = 0, j = 0;
        char tmp[129];
        while(x[i])
        {
            if((x[i] - '0') < 0 || (x[i] - '0') > 9)
            {
                tmp[j] = x[i];
                j++;
            }
            i++;
        }
        while(i-- > 0)
            x[i] = '';
        for(i = 0; i < j; i++)
        {
            x[i] = tmp[i];
        }
    }
    
    int main(void)
    {
        char str[129];
        printf("str:  "); scanf("%s", str);
        
        del_dit(str);
        printf("delete digit result: %s
    ", str);
        return 0; 
    }

    2、

    #include <stdio.h>
    
    void del_dig(char x[])
    {
        int i = 0;
        while(x[i])
        {
            if(x[i] >= '0' && x[i] <= '9')
                printf("");
            else
                putchar(x[i]);
            i++;
        }
    }
    
    int main(void)
    {
        char str[128];
        printf("str:  "); scanf("%s", str);
        
        del_dig(str);
        return 0;
    }

    3、

    #include <stdio.h>
    
    void del_dig(char x[])
    {
        int i = 0;
        while(x[i])
        {
            if(x[i] >= '0' && x[i] <= '9')
                i++;
            else
            {
                putchar(x[i]);
                i++;
            }
        }
    }
    
    int main(void)
    {
        char str[128];
        printf("str:  "); scanf("%s", str);
        
        del_dig(str);
        return 0;
    }

    4、

    #include <stdio.h>
    
    void del_dig(char x[])
    {
        int i = 0;
        while(x[i])
        {
            if(x[i] >= '0' && x[i] <= '9')
            {
                int j = i;
                while(x[j])
                {
                    x[j] = x[j + 1];
                    j++;
                }
                i--;
            }
            i++;
        }
        printf("result: %s
    ", x);
    }
    
    int main(void)
    {
        char str[128];
        printf("str: "); scanf("%s", str);
        
        del_dig(str);
        return 0;
    }

    5、

    #include <stdio.h>
    
    void del_digi(char x[])
    {
        int i = 0, j = 0;
        char tmp[128];
        while(x[i])
        {
            if(x[i] < '0' || x[i] > '9')
            {
                tmp[j] = x[i];
                j++;
            }
            i++;
        }
        for(i = 0; i < j; i++)
        {
            x[i] = tmp[i];
        }
        x[j] = '';
        printf("dig_del result: %s
    ", x); 
    }
    
    int main(void)
    {
        char str[128];
        printf("str:  "); scanf("%s", str);
        
        del_digi(str);
        return 0;
    }

  • 相关阅读:
    菜根谭#39
    菜根谭#38
    菜根谭#37
    菜根谭#36
    菜根谭#35
    菜根谭#34
    菜根谭#33
    菜根谭#32
    mysqli的使用
    mysql常用修改创建语句
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14814471.html
Copyright © 2020-2023  润新知