129.找出一位数组中最大值
2015-06-29 01:17
204 查看
函数fun的功能是:找出一维数组整型数组元素中最大的值和它所在的下标,最大值和它锁子啊的下标通过形参传回,数组元素中的值已在主函数中赋予。
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> void fun(int a[], int n, int *max, int *d) { int i; *max = a[0],*d=0; for (i = 0;i < n;i++) if (*max < a[i]) { *max = a[i]; *d = i; } } int main() { int i, x[20], max, index, n = 10; for (i = 0;i < n;i++) { x[i] = rand() % 50; printf("%4d", x[i]); } printf("\n"); fun(x, n, &max, &index); printf("Max=%5d, Index=%d\n", max, index); getchar(); return 0; }
相关文章推荐
- unity架构原则(摸索、增补中)
- 近期的目标
- 一个简单的sharepoint密码修改webpart
- IDNFeedParser 一个简单易用的Rss解析库(Objective-C)
- 枚举、typedef关键字
- 分布式数据库 Hbase 的高可用管理和监控
- zookeeper的单机安装和集群安装
- JavaScript中的getBoundingClientRect()方法
- PAT Maximum subsequence sum (Python)
- 权威支持: 用于实际故障诊断的功能和工具
- mongodb固定集合,建立管理员安全验证
- 使用xib开发界面
- android 图片合成
- PAT Shuffling machine (Python)
- 程序猿的修炼之路(一)
- SpringMVC莫名其妙出现No bean named 'cacheManager' is defined错误
- [Swust OJ 360]--加分二叉树(区间dp)
- 关于Android Studio第一次启动的Fetching android sdk component information的解决方法
- freemarker.core.InvalidReferenceException: Expression stackObject.value.get(propertyName).toString() is undefined
- iOS开发之xib技巧介绍