寻找数组最大值和下标

#include <stdio.h>
int search(int a[], int n)
{
	int i, max;
	max =0 ;
	for (i = 1; i<n; i++)
	{
		if(a[i]>a[max])
			max =max+i ;
	}
	return max;
}
int main()
{
	int a[10] = { 13, 1, -5, 4, 9, 100, -8, 7, -6, 2 };
	int max;
	max = search(a, 10);
	printf("最大值:%d, 下标:%d", a[max], max);
	while (1);
	return 0;
}

全部评论
感谢楼主对数组中找最大值的代码分享
点赞 回复 分享
发布于 2022-03-13 00:53

相关推荐

这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
你找工作的时候用AI吗?
点赞 评论 收藏
分享
兄弟们,实习都是在接各种api,该怎么包装简历
仁者伍敌:感觉我自己做小项目也是各种api啊,我要怎么包装简历
点赞 评论 收藏
分享
07-02 13:52
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务