寻找数组最大值和下标

#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

相关推荐

点赞 评论 收藏
分享
牛客83700679...:简历抄别人的,然后再投,有反馈就是简历不行,没反馈就是学历不行,多投多改只要技术不差机会总会有的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
1
分享

创作者周榜

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