zoukankan      html  css  js  c++  java
  • c语言 9-12

    1、

    #include <stdio.h>
    
    void rev_str(char x[][128], int n)
    {
        int i;
        for(i = 0; i < n; i++)
        {
            int j = 0;
            while(x[i][j])
                j++;
            while(j-- > 0)
                putchar(x[i][j]);
            putchar('
    ');
        }
    }
    
    int main(void)
    {
        char str[3][128];
        int i;
        for(i = 0; i < 3; i++)
        {
            printf("str[%d] = ", i); scanf("%s", str[i]);
        }
        puts("
    ====================");
        rev_str(str, 3);
        
        return 0;
    }

    2、

    #include <stdio.h>
    
    void rev(char x[][128], int n)
    {
        int i;
        for(i = 0; i < n; i++)
        {
            int j = 0;
            while(x[i][j])
                j++;
            int k;
            for(k = 0; k < j / 2; k++)
            {
                int tmp = x[i][k];
                x[i][k] = x[i][j - 1 - k];
                x[i][j - 1 - k] = tmp;    
            } 
        }
        for(i = 0; i < n; i++)
        {
            printf("x[%d]: %s
    ", i, x[i]);
        }
    }
    
    int main(void)
    {
        char str[3][128];
        int i;
        for(i = 0; i < 3; i++)
        {
            printf("str[%d] = ", i); scanf("%s", str[i]); 
        }
        puts("
    ====================");
        rev(str, 3);
        return 0;
    }

    3、

    #include <stdio.h>
    
    void rev_str(char x[][128], int n)
    {
        int i;
        for(i = 0; i < n; i++)
        {
            int j = 0;
            int len = 0;
            while(x[i][len])
                len++;
            while(x[i][j])
            {
                putchar(x[i][len - 1 - j++]);
            }
            putchar('
    ');
        }
    }
    
    int main(void)
    {
        char str[3][128];
        int i;
        for(i = 0; i < 3; i++)
        {
            printf("str[%d] = ", i); scanf("%s", str[i]);
        }
        puts("
    ======================");
        rev_str(str, 3);
        return 0;
    }

    4、

    #include <stdio.h>
    
    void rev_str(char x[][128], int n)
    {
        int i;
        char tmp[n][128];
        for(i = 0; i < n; i++)
        {
            int len = 0;
            while(x[i][len])
                len++;
            int j;
            for(j = 0; j < len; j++)
            {
                tmp[i][j] = x[i][len - 1 - j];
            }
            for(j = 0; j < len; j++)
            {
                x[i][j] = tmp[i][j];
            }
        }    
        
        for(i = 0; i < n; i++)
        {
            printf("x[%d] = %s
    ", i, x[i]);
        }
    } 
    
    int main(void)
    {
        char str[3][128];
        int i;
        for(i = 0; i < 3; i++)
        {
            printf("str[%d] = ", i); scanf("%s", str[i]);
        }
        puts("
    =======================");
        rev_str(str, 3);
        return 0;
    }

  • 相关阅读:
    快速搭建vue2.0开发环境
    node+websocket+react即时匿名通讯聊天室
    12月14日,Progress库
    12月9日,timer库
    12月7日,BOOST库安装及配置
    12月7日开始学习Boost
    is not allowed to connect to this MySQL server解决办法
    清华学堂练习题——传纸条
    makefile经典教程
    启动mysql服务命令
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/14815236.html
Copyright © 2011-2022 走看看