加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

找数组中的第二大数

发布时间:2020-12-14 03:03:50 所属栏目:大数据 来源:网络整理
导读:C语言找数组中的第二大数 #include stdio.h/*********************************************************** Function : findSecondMaxDescription: finded seconde max Parameter : int *a: array ine len: length of arrayReturn : s_maxDate: 2014.1.18Au

C语言找数组中的第二大数



#include <stdio.h>

/*********************************************************** 
Function   	: findSecondMax
Description	: finded seconde max 
Parameter  	: int *a: array
			  ine len: length of array
Return     	: s_max
Date		: 2014.1.18
Authot		: Puls	
************************************************************/
int findSecondMax(int *a,int len)
{
	int i,max,s_max;
	
	max = a[0];					/* max */
	s_max = a[1];				/* second max */
	
	for(i=0; i<len; i++)
	{
		if(a[i]>max)
		{
			s_max = max;		/* find s_max */
			max = a[i];			/* updata max number */
		}
		else if(a[i]<max && a[i]>s_max)		/* s_max < a[i] < max,so a[i] is second max  */
		{
			s_max = a[i];
		}
	}

	return s_max;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读