zoukankan      html  css  js  c++  java
  • c学习第1天

    2、自己实现strcpy函数//自己实现复制函数


    int strcpy_arr(char str1[], char str2[])
     {
     for(int i=0;arr1[i]!='';i++)
     {
        arr[i]=arr1[i];
     }
     arr[i]='';
     }

    //3、自己实现strlen函数

    int strlen_arr(char str[])//3、自己实现strlen函数
    {
        
    //    int count=0;
    //    while(*str!='') {
    //        count++;
    //        str++;
    //    }
    //    return count;
        //方法二
    //    int len=0;
    //    for (int i=0; str[i]!=''; i++) {
    //        len++;
    //    }
    //    return len;
        int i=0;
        while(str[i]!='')
        {
            i++;
        }
        return i;
        
    }

    //4、写一个函数将 tom is cat 反向打印成 cat is tom

    void reverse(char result[3][100],char arr[])
    {
        int j=0 ,s=0;
        for (int i=0; i<5; i++) {
            while (arr[j]!=' '&&arr[j]!='') {
                result[i][s++]=arr[j++];
               
            }
            j++;
         result[4][s]='';s=0;
        }printf("
    ");
    }

    //6题 789然后789输出

    //6题 789输入然后789输出
    void print_zhengxu(int num)
    {
            if (num == 0)
            {
                return;
            }
            print_zhengxu(num/10);
            printf("%d	", num%10);
    }

     //11、题目:打印出如下图案

         /*

       

        ***

        *****

        *******

        *****

        ***

       

        */

    在做这道题的时候,我们想想怎么打印

    ******

    ******

    ******

    肯定是

    for(int i=0;i<3;i++)

      {

        for  (int j=0;j<6;j++)

        {

          printf("*");

         }

        printf(" ");

      }

    由此可以联想,那么打印

    *

    **

    ***

    ****的代码为:

     for(int i=0;i<4;i++)
            
            {
                for (int j=0; j<=i; j++) {
                    printf("*");
                }
                printf("
    ");
            }

    到这里,我们可以想到,如果想每一行之间的打印都差两个,就要想到改变i自增的值了。

    int main ()
    { 
    for (int i=0; i<7; i+=2)
        {
            for (int j=0; j<=i; j++)
            {
                printf("* ");
            }
            printf("
    ");
        }
        for (int i=5; i>=0;i-=2) {
            for (int j=0; j<i; j++) {
                printf("* ");
            }
            printf("
    ");
        }
    return 0;
    }
  • 相关阅读:
    49. 字母异位词分组
    73. 矩阵置零
    Razor语法问题(foreach里面嵌套if)
    多线程问题
    Get json formatted string from web by sending HttpWebRequest and then deserialize it to get needed data
    How to execute tons of tasks parallelly with TPL method?
    How to sort the dictionary by the value field
    How to customize the console applicaton
    What is the difference for delete/truncate/drop
    How to call C/C++ sytle function from C# solution?
  • 原文地址:https://www.cnblogs.com/yinyakun/p/3385003.html
Copyright © 2011-2022 走看看