更多"主程序调用findmax函数求出数组中最大元素在数组中的下标,( )"的相关试题:
[单项选择]主程序调用findmax函数求出数组中最大元素在数组中的下标,括号中需填写的内容是
#include<stdio.h>
findmax(int*s,int t,int*k)
int p;
for(p=0,*k=p;p<t;p++)if(s[p]>s[*k])( );
main( )
int a[10],i,k;
for(i=0;i<10;i++)scanf("%d",&a[i]);
findmax(a,10,&k);
printf("%d%d/n" ,k,a[k]);
A. k=p
B. *k=p
C. k=p-s
D. *k=p-s
[简答题]编写一个函数fun( ),其功能是求出一个2×M整型二维数组中最大元素的值,并将此值返回调用函数。
#include<stdio.h>
#define M 4
int fun(int a[][M])
main( )
int arr[2][M]=5,8,3,45,76,-4,12,82);void NONO( );
printf("max=%d/n",fun(arr));
[简答题]下列给定程序中,函数fun( )的功能是:求出数组中最大数和次最大数,并把最大数和b[0]中的数对调、次最大数和b[1]中的数对调。
请修改程序中的错误,得出正确的结果。
注意:不要改动math( )函数,不能增行或删行,也不能更改程序的结构。
试题程序:
#include<conio.h>
#include<stdio.h>
#define N 10
//****error****
void fun( )
{
int i, m, t, j;
for(i=0; i<2; i++)
{
//****error****
m=0;
for(j=i+1; j<n; j++)
if(b[j]>b[m])
m=j;
t=b[i];
b[i]=b[m];
b[m]=t;
}
}
void main( )
{
int a[N]={5, 12, 9, 7, 10}, n=5, i;
for(i=0; i<n; i++)
printf("%d", a[i]);
printf("/n");
fun(a, n);
for(i=0; i<n; i++)
printf("%d", a[i]);
printf("/n");
}
[简答题]请编写一个函数fun( ),它的功能是:求出一个2×M整型二维数组中最大元素的值,并将此值返回调用函数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fan的花括号中填入所编写的若干语句。
试题程序:
#define M 4
#include <stdio.h>
fun(int a[] [M])
main( )
int arr[2][M]=5, 8, 3, 45, 76, -4, 12, 82;
printf("max=%d/n",fun(arr));
[简答题]下列程序定义了NXN的二维数组,并在主函数中赋值。请编写函数fun( ),函数的功能是求出数组周边元素的平方和并作为函数值返回给主函数中的s。例如:若a数组中的值为
a=0 1 2 7 9
1 11 21 5 5
2 21 6 11 1
9 7 9 10 2
5 4 1 4 1
则返回主程序后s的值应为310。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 5
int fun (int w[][N])
{
}
main( )
{
int a[N][N]={0,1,2,7,9,1,11,21,5,5,2, 21,6,11,1,9,7,9,10,2,5,4,1,4,1};
int i,j;
int s;
clrscr( );
printf("*****The array***+*/n");
for (i=0;i<N;i++)
{ for(j=0;j<N;i++)
{printf("%4d",a[i][j]);}
printf("/n");
}
s=fun(a);
printf("*****THE RESULT*****/n");
printf("The sum is:%d/n",s);
}
[填空题]以下函数用来求出数组的最大元素在数组中的下标并存放在k所指的存储单元中。请填空。
#include<conio.h>
#include<stdio.h>
int fun(int *s,int t,int *k)
{int i;
*k=0;
[8]
if(s[*k]<s[i])*k=i;
return [9] ;}
main( )
{ int a[10]:{876,675,896,101,301,401,980,431,451,777},k;
fun(a,10,&k);
pfintf("%d,%d/n",k,a[k]);}
[填空题]以下函数用来求出数组的最大元素在数组中的下标并存放在k所指的存储单元中。请填空。
#include<iostream.h>
void fun(int * s,int t,int * k)
int i;
* k= 【9】 ;
【10】
if(s[ * k] < s[i]) * k=i;
void main( )
int a[l0]= 876,675,896,101,301,401,980,431,451,777 ,k;
fun(a,10,&k);
cout < < k < <"," < < a[k];
[简答题]下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun( ),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如:若a数组中的值为
a= 0 1 2 7 9
1 9 7 4 5
2 3 8 3 1
4 5 6 8 2
5 9 1 4 1
则返回土程序后s的值应为3.375。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的仟何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
#include<conio.h>
#include<stdlib.h>
#define N 5
double fun (int w[] [N])
{
}
main( )
{
int a[N] [N]={0,1,2,7,9,1,9,7,4,5,2,
3,8,3,1,4,5,6,8,2,5,9,1,4,1};
int i, j;
double s;
clrscr( );
printf("*****The array*****/n ");
for (i=0; i<N; i++)
{ for (j=0;j<N;i++)
{printf("%4d ",a[i] [j]);}
printf("/n ");
}
s=fun(a);
printf("*****THE RESULT*****/n ");
printf("The sum is : %lf/n ",s);
}
[简答题]下列程序定义了M×M的二维数组,并在主函数中赋值。请编写函数proc( ),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为:
a=0 1 2 3 4
5 9 7 4 5
4 3 8 3 6
3 5 6 8 7
2 1 0 9 8
则返回主程序后,S的值为3.750000。
注意:部分源程序已给出。
请勿改动主函数main和其他函数中的任何内容。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define M 5
double proc(int w[][M])
void main( )
int a[M][M]=0, 1, 2, 3, 4, 5, 9, 7, 4, 5, 4, 3, 8, 3, 6, 3, 5, 6, 8, 7, 2, 1, 0, 9, 8;
int i, j;
double s;
system("CLS");
printf("*****The array*****/n");
for(i=0; i<M; i++)
for(j=0; j<M; j++)
printf("%4d", a[i][j]);
printf("/n");
s=proc(a);
printf("*****THE RESULT*****/n");
printf("The sum is: %lf/n", s);
[简答题]请编写函数fun,其功能是:找出2xM整型二维数组中最大元素的值,并将此值返回调用函数。
注意:部分源程序给出如下。
请勿改动主函数mam和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#define M 4
#include <stdio.h>
int fun (int a[][M])
void main ( )
int arr[2][M]=5, 8, 3, 45, 76,
4, 12, 82;
printf("max=% d/n", fun(arr));