一、程序填空題
1、給定程序中,函數(shù)fun的功能是根據(jù)形參i的值返回某個函數(shù)的值。當(dāng)調(diào)用正確時, 程序輸出:
x1=5.000000, x2=3.000000, x1*x1+x1*x2=40.000000
請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除, 使程序得出正確的結(jié)果。
注意:源程序存放在考生文件夾下的BLANK1.C中。
不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
#include
double f1(double x)
{ return x*x; }
double f2(double x, double y)
{ return x*y; }
/**********found**********/
__1__ fun(int i, double x, double y)
{ if (i==1)
/**********found**********/
return __2__(x);
else
/**********found**********/
return __3__(x, y);
}
main()
{ double x1=5, x2=3, r;
r = fun(1, x1, x2);
r += fun(2, x1, x2);
printf("\nx1=%f, x2=%f, x1*x1+x1*x2=%f\n\n",x1, x2, r);
}
2、給定程序中,函數(shù)fun的功能是:找出形參s所指字符串中出現(xiàn)頻率的字母(不區(qū)分大小寫),并統(tǒng)計出其出現(xiàn)的次數(shù)。
例如,形參s所指的字符串為:abcAbsmaxless,程序執(zhí)行后的輸出結(jié)果為:
letter 'a' : 3 times
letter 's' : 3 times
請在程序的下劃線處填入正確的內(nèi)容并把下劃線刪除, 使程序得出正確的結(jié)果。
注意:源程序存放在考生文件夾下的BLANK1.C中。
不得增行或刪行,也不得更改程序的結(jié)構(gòu)!
#include
#include
#include
void fun(char *s)
{ int k[26]={0},n,i,max=0; char ch;
while(*s)
{ if( isalpha(*s) ) {
/**********found**********/
ch=tolower(__1__);
n=ch-'a';
/**********found**********/
k[n]+= __2__ ;
}
s++;
/**********found**********/
if(max
}
printf("\nAfter count :\n");
for(i=0; i<26;i++)
if (k[i]==max) printf("\nletter \'%c\' : %d times\n",i+'a',k[i]);
}
main()
{ char s[81];
printf("\nEnter a string:\n\n"); gets(s);
fun(s);
}