1.下列给定程序中,函数fun的功能是:将大写字母转换为对应小写字母之后的第5字母;若小写字母为v~z,使小写字母的值减21。转换后的小写字母作为函数值返同。例如,若形参是字母A,则转换为小写字母f。形参是字母W,则转换为小写字母b。
#include <stdio.h>
#include <ctype.h>
char fun(char c)
{ if( c>='A' && c<='Z')
c=c+32;
if(c>='a' && c<='u')
/**************found**************/
c=c+___1___;
else if(c>='v'&&c<='z')
c=c-21;
/**************found**************/
return ___2___ ;
}
main()
{ char c1,c2;
printf("\nEnter a letter(A-Z): ");
c1=getchar();
if( isupper( c1 ) ) {
/**************found**************/
c2=fun(___3___);
printf("\n\nThe letter \'%c\' change to \'%c\'\n", c1,c2);
}
else printf("\nEnter (A-Z)!\n");
}
2.函数fun的功能是进行字母转换。若形参ch中是小写英文字母,则转换成对应的大写英文字母:若ch中是大写英文字母,则转换成对应的小写英文字母;若是其他字符,则保持不变,并将转换后的结果作为函数值返回。
请在程序的下划线处填入正确的内容,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
#include <ctype.h>
char fun(char ch)
{
/**********found**********/
if ((ch>='a')___1___(ch<='z'))
return ch -'a' + 'A';
if ( isupper(ch) )
/**********found**********/
return ch +'a'-___2___ ;
/**********found**********/
return ___3___;
}
main()
{ char c1, c2;
printf("\nThe result :\n");
c1='w'; c2 = fun(c1);
printf("c1=%c c2=%c\n", c1, c2);
c1='W'; c2 = fun(c1);
printf("c1=%c c2=%c\n", c1, c2);
c1='8'; c2 = fun(c1);
printf("c1=%c c2=%c\n", c1, c2);
}
3.给定程序中,函数fun的功能是计算下式例如,若形参e的值为1e-3,函数的返回值2.985678。请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。注意:源程序存放在考生文件夹下的BLANKl.C中。不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
double fun(double e)
{ int i; double s, x;
/**********found**********/
s=0; i=__1__;
x=1.0;
while(x>e){
/**********found**********/
__2__;
/**********found**********/
x=(2.0*i-1)/((__3__)*(2.0*i));
s=s+x;
}
return s;
}
main()
{ double e=1e-3;
printf("\nThe result is: %f\n",fun(e));
}
4.八进制转换为十进制
#include <stdio.h>
int fun(char *p)
{
}
//声明函数
void NONO ();
int main( )
{
char *p,s[6];
p=s;
printf("请输入数字字符串:");
gets(p);
printf("转换成十进制的结果为:%d\n",fun(p));
NONO ();
return 0;
}
void NONO()
{/* 请在此函数内打开文件,输入测试数据,调用 fun 函数,输出数据,关闭文件。 */
FILE *rf, *wf ;
int i;
char *q,m[6];
rf = fopen("in.dat", "r") ;
wf = fopen("out.dat", "w") ;
for(i = 0 ; i < 6 ; i++) {
fscanf(rf, "%s", m) ;
}
q=m;
fprintf(wf, "%d\n",fun(q) ) ;
fclose(rf) ; fclose(wf) ;
}