爱问知识人 爱问教育 医院库

C语言编程

首页

C语言编程

如何查找一个数组第二大数字的下标,假设数组是{0 1 3 4 5 2 8}

提交回答
好评回答
  • 2012-04-13 08:05:16
      #include 
    int array[] = { 11, 1, 3, 4,119, 12, 119, 5, 2, 8 };
    int main(int argc, char** argv)
    {
      int max_index = 0;
      int sec_index = 0;
      int i = 0;
      /* search for the largest one */
      for( i=1; iarray[max_index])
         {
            max_index = i;
         }
      }
      /* the initial sec_index should not equal to max_index。
       */ if( max_index == 0 ) sec_index = 1; /* search for the second largest one */ for( i=0; iarray[sec_index]) && (array[i] != array[max_index]) ) { sec_index = i; } } printf("theindexoflargestnumberinthearrayis% lueis:%d\n",max_index,array[max_index]); printf("theindexofsecondlargestnumberinthearrayis% lueis:%d\n",sec_index,array[sec_index]); getch(); }。
      

    n***

    2012-04-13 08:05:16

其他答案

类似问题

换一换
  • 软件 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):