网友您好, 请在下方输入框内输入要搜索的题目:
试题二
下面程序中函数fun的功能是:在含有10 个元素的s数组中查找最大数,及最大数所在位置(即,下标值),最大数可能不止一个。最大数作为函数值返回,最大数的个数通过指针变量n传回,所在位置由数组pos传回。
例如:
若输入 2 8 5 7 8 4 5 3 2 8
则应输出:
The max: 8
Total: 3 //最大数出现次数
The positions: 1 4 9
请补充下列空缺:
include<stdio.h>
include<conio.h>
define M 10
int fun(int *a, int *n, int pos[])
{int i, k,max=-32767;
(1)
for(i=0; i<M; i++)
if( (2) ) max=a[i];
for(i=0; i<M; i++)
if( (3) )pos[k++]=i;
*n=k;
return max;
}
main()
{int a[M], pos[M], i=0, j, n;
clrscr();
printf("Enter 10 number :");
for(i=0; i<M; i++)scanf("%d", (4));
j=fun( (5) );
printf("The max: %d\n", j);
printf("Total: %d",n);
printf("The position:");
for(i=0; i<n; i++ ) printf("%4d", pos[i]);
printf("\n");
}
参考答案
更多 “ 试题二下面程序中函数fun的功能是:在含有10 个元素的s数组中查找最大数,及最大数所在位置(即,下标值),最大数可能不止一个。最大数作为函数值返回,最大数的个数通过指针变量n传回,所在位置由数组pos传回。例如:若输入 2 8 5 7 8 4 5 3 2 8则应输出:The max: 8Total: 3 //最大数出现次数The positions: 1 4 9请补充下列空缺:includestdio.hincludeconio.hdefine M 10int fun(int *a, int *n, int pos[]){int i, k,max=-32767;(1)for(i=0; iM; i++)if( (2) ) max=a[i];for(i=0; iM; i++)if( (3) )pos[k++]=i;*n=k;return max;}main(){int a[M], pos[M], i=0, j, n;clrscr();printf(Enter 10 number :);for(i=0; iM; i++)scanf(%d, (4));j=fun( (5) );printf(The max: %d\n, j);printf(Total: %d,n);printf(The position:);for(i=0; in; i++ ) printf(%4d, pos[i]);printf(\n);} ” 相关考题
![瑞牛题库 章节练习 历年真题 模拟试卷](http://assets.51tk.com/51_sidebar_right_index.jpg)