在考生文件夾下,給定程序MODI.C的功能是:
求一維數(shù)組a中的最大元素及其下標(biāo)。
例如,當(dāng)一維數(shù)組a中的元素為:34,4,2,7,3,12,5,8,5,9,
程序的輸出應(yīng)為:The max is: 34,pos is: 0 。
#include
#include
int max;
maxarr(int arr[ ])
{
int pos,i;
/************found************/
max=arr[0]; |
pos = 0;
for ( i=1; i<10; i++)
if (max < arr[i])
{
max = arr[i];
pos = i;
}
/************found************/
return(pos); |
}
main()
{
int a[10]={34,4,2,7,3,12,5,8,5,9};
printf("The max is: %d ,pos is: %d\n", max , maxarr(a));
}
2015年全國職稱計算機(jī)考試教材(2007模 .. 定價:¥225 優(yōu)惠價:¥213 更多書籍 | |
全國職稱計算機(jī)考試速成過關(guān)系列套裝:W .. 定價:¥133 優(yōu)惠價:¥133.0 更多書籍 |