机试练习1.docx

上传人:b****7 文档编号:25155383 上传时间:2023-06-05 格式:DOCX 页数:35 大小:22.39KB
下载 相关 举报
机试练习1.docx_第1页
第1页 / 共35页
机试练习1.docx_第2页
第2页 / 共35页
机试练习1.docx_第3页
第3页 / 共35页
机试练习1.docx_第4页
第4页 / 共35页
机试练习1.docx_第5页
第5页 / 共35页
点击查看更多>>
下载资源
资源描述

机试练习1.docx

《机试练习1.docx》由会员分享,可在线阅读,更多相关《机试练习1.docx(35页珍藏版)》请在冰豆网上搜索。

机试练习1.docx

机试练习1

第一套

给定程序的功能是:

求二分之一的圆面积,函数通过形参得到圆的半径,函数返回二分之一的圆面积(注:

圆面积公式为:

2,在程序中定义的变量名要与公式的变量相同)。

例如,输入圆的半径值:

19.527,输出为:

s=598.949991。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。

试题程序:

#include

doublefun(doubler)

{

return3.14159*【1】/2.0;

}

voidmain()

{

doublex;

printf("Enterx:

");

scanf("%lf",【2】);

printf("s=%lf\n",fun(【3】));

}

下列给定程序中,函数fun的功能是:

计算S=f(-n)+f(-n+1)+…+f(0)+f

(1)+f

(2)+…f(n)的值。

例如,当n为5时,函数值应为10.407143。

f(x)函数定义如下:

f(x)=

请改正程序中的错误,使它能得出正确的结果。

注意:

不要改动main函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#include

#include

#include

#include

/*************found**************/

f(doublex)

{

if(x==0.0||x==2.0)

return0.0;

elseif(x<0.0)

return(x-1)/(x-2);

else

return(x+1)/(x-2);

}

doublefun(intn)

{

inti;doubles=0.0,y;

for(i=-n;i<=n;i++)

{y=f(1.0*i);s+=y;}

/*************found**************/

returns

}

voidmain()

{system("CLS");

printf("%f\n",fun(5));

}

编写函数fun,函数的功能是:

根据以下公式计算s,计算结果作为函数值返回;n通过形参传入。

S=1+1/(1+2)+1/(1+2+3)+…+1/(1+2+3+…+n)

例如,若n的值为11时,函数的值为1.833333。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

#include

#include

#include

#include

floatfun(intn)

{

}

voidmain()

{

FILE*wf;

intn;

floats;

system("CLS");

printf("\nPleaseenterN:

");

scanf("%d",&n);

s=fun(n);

printf("Theresultis:

%f\n",s);

/******************************/

wf=fopen("out.dat","w");

fprintf(wf,"%f",fun(11));

fclose(wf);

/*****************************/

}

第二套

请补充main函数,该函数的功能是:

计算两个自然数n和m(m<10000)之间所有数的和(n和m从键盘输入)。

例如,当n=1,m=100时,sum=5050;当n=100,m=1000时,sum=495550。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在main函数的横线上填入所编写的若干表达式或语句。

试题程序:

#include

#include

#include

voidmain()

{

intn,m;

longsum;

【1】;

system("CLS");

printf("\nInputn,m\n");

scanf("%d,%d",&n,&m);

while(n<=m)

{

【2】;

n++;

}

printf("sum=%【3】\n",sum);

}

下列给定程序中,fun函数的功能是:

根据形参m,计算下列公式的值:

t=1+1/2+1/3+1/4+…+1/m

例如,若输入5,则应输出2.283333。

请改正程序中的错误,使它能计算出正确的结果。

注意:

不要改动main函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#include

#include

#include

doublefun(intm)

{

doublet=1.0;

intI;

for(I=2;I<=m;I++)

/*************found**************/

t+=1.0/k;

/*************found**************/

returnI;

}

voidmain()

{intm;

system("CLS");

printf("\nPleaseenter1integernumber:

");

scanf("%d",&m);

printf("\nTheresultis%1f\n",fun(m));

}

 

请编写一个函数voidfun(char*tt,intpp[]),统计在tt字符串中"a"到"z"26个字母各自出现的次数,并依次放在pp所指数组中。

例如,当输入字符串abcdefghabcdeabc后,程序的输出结果应该是:

333221110000000000000000000

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

#include

#include

#include

voidfun(char*tt,intpp[])

{

}

voidmain()

{

FILE*wf;

charaa[1000];

intbb[26],k;

system("CLS");

printf("\nPleaseenteracharstring:

");

scanf("%s",aa);

fun(aa,bb);

for(k=0;k<26;k++)

printf("%d",bb[k]);

printf("\n");

/******************************/

wf=fopen("out.dat","w");

fun("abcdefgabcdeabc",bb);

for(k=0;k<26;k++)

fprintf(wf,"%d",bb[k]);

fclose(wf);

/*****************************/

}

第三套

给定程序的功能是:

判断字符ch是否与串str中的某个字符相同,若相同什么也不做,若不同则插在串的最后。

注意:

部分源程序给出如下。

请勿改动函数main和其他函数中的任何内容,仅在横线上填入所编写的若干表达式或语句。

试题程序:

#include

#include

voidfun(char*str,charch)

{

while(*str&&*str!

=ch)str++;

if(*str【1】ch)

{str[0]=ch;

【2】=0;

}

}

voidmain()

{chars[81],c;

system("CLS");

printf("\nPleaseenterastring:

");

gets(s);

printf("\nPleaseenterthecharactertosearch:

");

c=getchar();

fun(【3】);

printf("\nTheresultis%s\n",s);

}

下列给定程序中,函数fun的功能是:

分别统计字符串中大写字母和小写字母的个数。

例如,给字符串s输入:

AaaaBBb123CCccccd,则应输出结果:

upper=5,lower=9。

请改正程序中的错误,使它能计算出正确的结果。

注意:

不要改动main函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#include

#include

/*********found***********/

voidfun(char*s,inta,intb)

{

while(*s)

{

/*********found***********/

if(*s>='A'&&*s<='Z')

a++;

/*********found***********/

if(*s>='a'&&*s<='z')

b++;

s++;

}

}

main()

{

chars[100];

intupper=0,lower=0;

printf("\npleaseastring:

");

gets(s);

fun(s,&upper,&lower);

printf("\nupper=%dlower=%d\n",upper,lower);

}

 

请编写函数fun,它的功能是:

求出ss所指字符串中指定字符的个数,并返回此值。

例如,若输入字符串123412132,输入字符1,则输出3。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

#include

#include

#include

#defineM81

intfun(char*ss,charc)

{

}

voidmain()

{

FILE*wf;

chara[M],ch;

system("CLS");

printf("\nPleaseenterastring:

");

gets(a);

printf("\nPleaseenterachar:

");

ch=getchar();

printf("\nThenumberofthecharis:

%d\n",fun(a,ch));

/******************************/

wf=fopen("out.dat","w");

fprintf(wf,"%d",fun("123412132",'1'));

fclose(wf);

/*****************************/

}

第四套

请补充函数fun,该函数的功能是:

把ASCII码为偶数的字符从字符串str中删除,结果仍然保存在字符串str中,字符串str从键盘输入,其长度作为参数传入函数fun。

例如,输入"abcdef",输出"ace"。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。

试题程序:

#include

#include

#defineN80

【1】

{

inti,j;

【2】;

for(i=0;i

{

if(s[i]%2!

=0)

s[j++]=s[i];

}

【3】;

}

voidmain()

{

inti=0,strlen=0;

charstr[N];

system("CLS");

printf("\nInputastring:

\n");

gets(str);

while(str[i]!

='\0')

{

strlen++;

i++;

}

fun(str,strlen);

printf("\n***displaystring***\n");

puts(str);

}

下列给定程序中函数fun的功能是:

计算正整数num各位上的数字之积。

例如,若输入252,则输出应该是20。

若输入202,则输出应该是0。

请改正程序中的错误,使它能得出正确的结果。

注意:

不要改动main函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#include

#include

longfun(longnum)

{

/*************found**************/

longk;

do

{

k*=num%10;

/*************found**************/

num\=10;

}while(num);

return(k);

}

main()

{

intn;

printf("\Pleaseenteranumber:

");

scanf("%ld",&n);

printf("\n%ld\n",fun(n));

}

请编写一个函数fun,它的功能是:

求出1到m(含m)之内能被7或11整除的所有整数放在数组a中,通过n返回这些数的个数。

例如,若传给m的值为50,则程序输出:

711142122283335424449

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

#include

#include

#include

#defineM100

voidfun(intm,int*a,int*n)

{

}

voidmain()

{

FILE*wf;

intaa[M],n,k;

system("CLS");

fun(50,aa,&n);

for(k=0;k

if((k+1)%20==0)/*每行输出20个数*/

{printf("%4d",aa[k]);

printf("\n");

}

else

printf("%4d",aa[k]);

printf("\n");

/******************************/

wf=fopen("out.dat","w");

for(k=0;k

fprintf(wf,"%4d",aa[k]);

fclose(wf);

/*****************************/

}

第五套

请补充函数fun,该函数的功能是:

判断某一个年份是否为闰年。

例如,1900年不是闰年,2004是闰年。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。

试题程序:

#include

#include

#include

intfun(intn)

{

intflag=0;

if(n%4==0)

{

if(【1】)

flag=1;

}

if(【2】)

flag=1;

return【3】;

}

voidmain()

{

intyear;

system("CLS");

printf("Inputtheyear:

");

scanf("%d",&year);

if(fun(year))

printf("%disaleapyear.\n",year);

else

printf("%disnotaleapyear.\n",year);

}

下列给定程序中函数fun的功能是:

计算n!

例如,给n输入5,则输出120.000000。

请改正程序中的错误,使程序能输出正确的结果。

注意:

不要改动main函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#include

#include

doublefun(intn)

{doubleresult=1.0;

/*************found**************/

ifn==0

return1.0;

while(n>1&&n<170)

/*************found**************/

result=n--;

returnresult;

}

voidmain()

{

intn;

printf("InputN:

");

scanf("%d",&n);

printf("\n\n%d!

=%lf\n",n,fun(n));

}

请编写函数fun,其功能是:

将两个两位数的正整数a、b合并成一个整数放在c中。

合并的方式是:

将a数的十位和个位数依次放在c数的十位和千位上,b数的十位和个位数依次放在c数的个位和百位上。

例如,当a=45,b=12,调用该函数后,c=5241。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

#include

#include

voidfun(inta,intb,long*c)

{

}

voidmain()

{

inta,b;

longc;

FILE*out;

printf("Inputa,b:

");

scanf("%d%d",&a,&b);

fun(a,b,&c);

printf("Theresultis:

%ld\n",c);

/******************************/

out=fopen("out.dat","w");

fun(a+11,b+22,&c);

fprintf(out,"%ld\n",c);

fclose(out);

/******************************/

}

第六套

请补充函数fun,函数fun的功能是求n的阶乘。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。

试题程序:

#include

longfun(intn)

{

if(【1】)

return(n*fun(【2】));

return【3】;

}

voidmain()

{

printf("10!

=%ld\n",fun(10));

}

下列给定的程序中,函数fun的功能是:

计算并输出k以内最大的10个能被13或17整除的自然数之和。

k的值由主函数传入,若k的值为500,则函数的值为4622。

请改正程序中的错误,使它能得出正确的结果。

注意:

不要改动main函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#include

#include

#include

intfun(intk)

{intm=0,mc=0,j;

while((k>=2)&&(mc<10))

{

/*************found**************/

if((k%13=0)||(k%17=0))

{m=m+k;mc++;}

k--;

/*************found**************/

returnm;

}

voidmain()

{system("CLS");

printf("%d\n",fun(500));

}

请编写函数fun,它的功能是计算:

s=(ln

(1)+ln

(2)+ln(3)+…+ln(m))0.5

在C语言中可调用log(n)函数求ln(n)。

例如,若m的值为20,则fun函数值为6.506583。

注意:

部分源程序给出如下。

请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

试题程序:

#include

#include

#include

#include

doublefun(intm)

{

}

voidmain()

{

FILE*wf;

system("CLS");

printf("%f\n",fun(20));

/******************************/

wf=fopen("out.dat","w");

fprintf(wf,"%f",fun(20));

fclose(wf);

/*****************************/

}

第七套

请补充函数fun,该函数的功能是:

整除x且是偶数的数,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1