时间:2012-04-06 22:11:10
第二十套
1程序填空
给定程序中,函数fun的功能是:计算形参x所指数组中N个数的平均值,(规定所有数均为正数),将所指桑骂槐数组中小于平均值的数据移至数据的前部,大于等于平均值的数据移至x决指数组的后部,平均值作为函数值返回,在主函数中输出平均值和移动后的数据。
第1处 for(i=0; i<N; i++) av+=x[i]/N
第2处 y[j]=x[i]; x[i]=-1; j++;}
第3处 i++;
2程序修改
给定程序MODI1.C函数fun的功能是:统计字符串各元音字母(即:A、E、I、O、U)的个数。注意字母不分大、小写。
#include <stdio.h>
fun (char *s, int num[5])
{ int k, i=5;
for(k=0;k<i;k++)
/*******found******/
num[k]=0;
for( ; *s;s++)
{ i=-1;
/*******found******/
switch( *s)
{ case ‘a’;case ‘A’;
{i=0;break;}
{ case ‘e’;case ‘E’;
{i=1;break;}
{ case ‘i’;case ‘I’;
{i=2;break;}
{ case ‘o’;case ‘O’;
{i=3;break;}
{ case ‘u’;case ‘U’;
{i=4;break;}
}
if (i>=0)
num[i]++;
}
}
3程序设计
请编写函数fun,函数的功能是求出二级数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
#include <stdio.h>
#define M 4
#define N 5
int fun(int a [M][N])
{
int tot = 0, i,j;
for(i=0;i<N;i++)
{
tot +=a[0][i];
tot +=a[M-1][i];
}
for (i=1;i<M-1;i++){
tot +=a[i][0];
tot +=a[i][N-1];
}
return tot;
}