未分类题

阅读以下说明和C语言函数,将应填入(n)处。
[说明]
函数int find_Max_Min(int a[],int n)的功能是:找出n个元素的数组a中的最大元素和最小元素并输出,返回查找过程中元素的比较次数。查找方法如下:比较a[0]和a[n-1],若a[0]大,则交换a[0]和a[n-1]的值:再比较a[1]和a[n-2],若a[1]大,则交换a[1]和a[n-2]的值;以此类推,直到所有的元素都比较完。然后在数组的前半区从前往后找出小元素,在后半区从后往前找出大元素。
[函数]
int find_Max_Min(int a[],int n)
{/*找出n个元素的数组a的最大、最小元素并输出,返回查找过程元素中的比较次数*/
int i,Count=0;
int temp,Maxnum,Minnum;
for(i=0; i<n/2; i++){
Count=Count+1 /*元素比较次数计数*/
if(a[i]>a[(1)])
{/*数组元素交换代码略*/}
}
Maxnum=a[n-1]; Minnum=a[0];
for(i=1;i<n/2+n%2;i++){
Count=(2); /*元素比较次数计数*/
Minnum=(3)? a[i]:Minnum; /*找最小元素*/
Maxnum=(4)?(5):Maxnum; /*找最大元素*/
}
printf('Max=%d/n',Maxnum);
printf('Min=%d/n',Minnum);
return Count;
}

【参考答案】

(1)n-i-1(2)Count+2(3)a[i]<Minnum(4)a[n-i-1]>Maxnum(5)a[n-i-1......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

未分类题
Kuwait is a country which is quite small, but which is quite rich. Ithas a population of a little more than a million, and it is situated at thenorth end of the Persian GulF.This small desert country is onE.., the 【M1】_______.world's leading oil producers and it has approximately 15 percentage of the 【M2】_______.world's known petroleum reserves. Since the discovery of oil in 1938, Ku-wait's rulers had turned the country into a prosperous welfare statE.It has free 【M3】_______.primary and secondary education, free healthy care and social services; and the 【M4】_______.Kuwaitis do not have to pay any personal income fax for those services.The rate of literacy is high and constantly grow. The university of Kuwait was 【M5】_______.open in 1966, but many of the Kuwaiti students still study in colleges anduniversities abroad, on state expensE.Kuwait is, needless to point out, an 【M6】_______.Arab country, and the majority of tile people who live there are Moslems. 【M7】_______.But fewer than half of these Moslems are actually citizens of Kuwait. Thisis because there arc many Moslem emigrant living and working therE.Man- 【M8】_______.y of these people have come from all over the Arab world-from places likeEgypt, Syria, Lebanon, and from the Sudan. The minority of the population,in other word the non Moslems, have come to this country because 【M9】_______.they were attracted by the opportunities to work for the oil companies.There are several thousands Europeans and Americans in Kuwait. Many of 【M10】_______.them are employed by the oil companies.【M1】
A..,
B.
world's
C.
world's
D.
primary
E.
Kuwaitis
F.
The
G.
open
H.
Arab
I.
But
J.
y
K.
they
L.
them
M.
【M1】