zoukankan      html  css  js  c++  java
  • 求数组中第二大的值

    /*

    所有c语言代码,都是在LoadRunner中运行;

    */
    Action()
    {
      int a[]={12,34,565,23,24,667,89,98};//定义一个int数组;
      int len;//记录数组元素个数;
      int max;//所求的最大值;
      int max_2;//第二大的值;
      int i;//循环变量;LoadRunnerg中,不能在for循环中定义变量;

      len = sizeof(a)/sizeof(int);//数组元素个数=数组所占字符数/数组元素类型所占字符数;
      max = a[0];
      for (i = 0;i < len;i ++) {
        if (max < a[i]) {
        max = a[i];
        }
      }
      lr_output_message("数组a[]的最大的值是==%d==",max);

      max_2 = a[0];
      for (i = 0;i < len;i ++) {
        if ((max_2 < a[i])&&(a[i] < max)) {
        max_2 = a[i];
        }
      }
      lr_output_message("数组a[]的第二大的值是==%d==",max_2);

      return 0;
    }

    ===========================================================================================

    运行结果

    Action.c(21): 数组a[]的最大的值是==667==
    Action.c(29): 数组a[]的第二大的值是==565==

    ===========================================================================================

  • 相关阅读:
    黑马程序员_java基础笔记(13)...类加载器和代理
    nyoj-411-Friends number
    nyoj-38-布线问题
    nyoj-233-Sort it
    nyoj-115-城市平乱
    nyoj-608-畅通工程
    nyoj-36-最长公共子序列
    nyoj-150-Train Problem I
    nyoj-494-Dancing With the Googlers
    nyoj-214-单调递增子序列(二)
  • 原文地址:https://www.cnblogs.com/beidou93/p/9716198.html
Copyright © 2011-2022 走看看