zoukankan      html  css  js  c++  java
  • Linux 系统编程实战——4.7习题

    3.编写一个函数,从字符串s的第i个字符开始删除n个字符(注意要检查输入参数)

    4.用递归方法求一个n个数的整形数组的最大值

     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<stdlib.h>
     4 
     5 void deleteStr(char *param, int startIndex, int number) {
     6    char *result = param;
     7    int i, length = startIndex + number;
     8 
     9    if(NULL == param || length  > strlen(param)) {
    10      printf("ERROR");
    11      return ;           
    12   } else {
    13      for(i = 0; i < strlen(param)-length; i++) {
    14         *(result + startIndex + i) = *(result + length + i);       
    15      }
    16      *(result + length) = '';
    17      printf("%s", result);
    18   }
    19 }
      int getMax(int *array, int n) {
        if(1 == n) {
          return *array;
        } else {
          if(*array > getMax(array+1, n-1)) {
            return *array;
          } else {
            return getMax(array+1, n-1); 
          }
        }
      }
    20 21 int main() { 22 char str[] = "12345"; 23 int startIndex = 1; 24 int number = 2; 25 26 deleteStr(str, startIndex, number); 27 28 return 0; 29 }
  • 相关阅读:
    设计模式之四 代理模式
    设计模式之四 建造者模式
    设计模式之三 模板模式
    设计模式之二 工厂模式
    如何使用Json-lib
    Java LoggingAPI 使用方法
    设计模式之一 单例模式
    Scrapy教程
    Scrapy简介
    Scrapy安装向导
  • 原文地址:https://www.cnblogs.com/AI-Cobe/p/10250855.html
Copyright © 2011-2022 走看看