计算机二级C最新上机试题库Word文档格式.docx

上传人:b****1 文档编号:954715 上传时间:2023-04-29 格式:DOCX 页数:460 大小:173.08KB
下载 相关 举报
计算机二级C最新上机试题库Word文档格式.docx_第1页
第1页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第2页
第2页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第3页
第3页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第4页
第4页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第5页
第5页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第6页
第6页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第7页
第7页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第8页
第8页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第9页
第9页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第10页
第10页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第11页
第11页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第12页
第12页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第13页
第13页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第14页
第14页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第15页
第15页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第16页
第16页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第17页
第17页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第18页
第18页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第19页
第19页 / 共460页
计算机二级C最新上机试题库Word文档格式.docx_第20页
第20页 / 共460页
亲,该文档总共460页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

计算机二级C最新上机试题库Word文档格式.docx

《计算机二级C最新上机试题库Word文档格式.docx》由会员分享,可在线阅读,更多相关《计算机二级C最新上机试题库Word文档格式.docx(460页珍藏版)》请在冰点文库上搜索。

计算机二级C最新上机试题库Word文档格式.docx

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;

returns

{system("

CLS"

%f\n"

fun(5));

3.程序设计题

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

根据以下公式计算s,计算结果作为函数值返回;

n通过形参传入。

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

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

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

string.h>

floatfun(intn)

}

FILE*wf;

intn;

floats;

system("

\nPleaseenterN:

%d"

&

n);

s=fun(n);

Theresultis:

%f\n"

s);

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

wf=fopen("

out.dat"

"

w"

fprintf(wf,"

%f"

fun(11));

fclose(wf);

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

【参考答案】:

1.

(1)r*r

(2)&

x(3)x

.2.

(1)错误:

f(doublex)正确:

doublef(doublex)

2)错误:

returns正确:

returns;

3.floatfun(intn)

inti,s1=0;

/*定义整型变量s1,表示分母*/

floats=0.0;

/*定义单精度变量s,表示每一项*/

for(i=1;

i<

i++){

s1=s1+i;

/*求每一项的分母*/

s=s+1.0/s1;

/*求多项式的值*/

}

第2套

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

计算两个自然数n和m(m<

10000)之间所有数的和(n和m从键盘输入)。

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

当n=100,m=1000时,sum=495550。

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

试题程序:

intn,m;

longsum;

【1】;

\nInputn,m\n"

%d,%d"

n,&

m);

while(n<

=m)

{

【2】;

n++;

sum=%【3】\n"

sum);

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

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

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

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

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

doublefun(intm)

doublet=1.0;

intI;

for(I=2;

I<

=m;

I++)

t+=1.0/k;

returnI;

{intm;

\nPleaseenter1integernumber:

\nTheresultis%1f\n"

fun(m));

请编写一个函数voidfun(char*tt,intpp[]),统计在tt字符串中"

a"

到"

z"

26个字母各自出现的次数,并依次放在pp所指数组中。

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

333221110000000000000000000

voidfun(char*tt,intpp[])

voidmain()

charaa[1000];

intbb[26],k;

\nPleaseenteracharstring:

);

%s"

aa);

fun(aa,bb);

for(k=0;

k<

26;

k++)

%d"

bb[k]);

\n"

fun("

abcdefgabcdeabc"

bb);

fprintf(wf,"

1.

(1)sum=0

(2)sum+=n(3)ld

2.

(1)错误:

t+=1.0/k;

正确:

t+=1.0/I;

(2)错误:

returnI;

returnt;

3.voidfun(char*tt,intpp[])

for(i=0;

26;

i++)

pp[i]=0;

/*初始化pp数组各元素为0*/

for(;

*tt!

='

\0'

;

tt++)

if(*tt>

a'

&

*tt<

z'

pp[*tt-'

]++;

/*将tt字符串中'

到'

26个字母各自出现的次数,依次放在pp数组中,任一个小写字母减去'

后所得结果正好是它对应的下标*/

第3套

1.程序填空题

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

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

voidfun(char*str,charch)

while(*str&

*str!

=ch)str++;

if(*str【1】ch)

{str[0]=ch;

【2】=0;

{chars[81],c;

\nPleaseenterastring:

gets(s);

\nPleaseenterthecharactertosearch:

c=getchar();

fun(【3】);

\nTheresultis%s\n"

s);

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

例如,给字符串s输入:

AaaaBBb123CCccccd,则应输出结果:

upper=5,lower=9。

#include<

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

voidfun(char*s,inta,intb)

while(*s)

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

if(*s>

A'

&

*s<

Z'

a++;

b++;

s++;

main()

chars[100];

intupper=0,lower=0;

\npleaseastring:

"

gets(s);

fun(s,&

upper,&

lower);

\nupper=%dlower=%d\n"

upper,lower);

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

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

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

#defineM81

intfun(char*ss,charc)

chara[M],ch;

\nPleaseenterastring:

gets(a);

\nPleaseenterachar:

ch=getchar();

\nThenumberofthecharis:

%d\n"

fun(a,ch));

fun("

123412132"

'

1'

));

1.

(1)!

=

(2)str[1]或*(str+1)(3)s,c

voidfun(char*s,inta,intb)

正确:

voidfun(char*s,int*a,int*b)

a++;

(*a)++;

(3)错误:

b++;

(*b)++;

3.intfun(char*ss,charc)

inti=0;

for(;

*ss!

\0'

ss++)

if(*ss==c)

i++;

/*求出ss所指字符串中指定字符的个数*/

returni;

第4套

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

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

例如,输入"

abcdef"

输出"

ace"

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

#defineN80

【1】

inti,j;

【2】;

for(i=0;

n;

if(s[i]%2!

=0)

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

【3】;

inti=0,strlen=0;

charstr[N];

\nInputastring:

\n"

gets(str);

while(str[i]!

strlen++;

i++;

fun(str,strlen);

\n***displaystring***\n"

puts(str);

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

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

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

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

longfun(longnum)

longk;

do

k*=num%10;

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

num\=10;

}while(num);

return(k);

\Pleaseenteranumber:

%ld"

\n%ld\n"

fun(n));

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

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

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

711142122283335424449

#defineM100

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

intaa[M],n,k;

fun(50,aa,&

for(k=0;

k++)

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

{printf("

%4d"

aa[k]);

1.

(1)voidfun(chars[],intn)

(2)j=0

(3)s[j]='

longk;

longk=1;

num\=10;

正确:

num/=10;

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

inti,j=0;

if(i%7==0||i%11==0)

/*求出1到m(含m)之内能被7或11整除的所有整数放在数组a中*/

a[j++]=i;

*n=j;

/*返回这些数的个数*/

第5套

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

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

intfun(intn)

intflag=0;

if(n%4==0)

if(【1】)

flag=1;

if(【2】)

flag=1;

return【3】;

intyear;

Inputtheyear:

year);

if(fun(year))

printf("

%disaleapyear.\n"

year);

else

%disnotaleapyear.\n"

2.程序改错题

计算n!

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

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

{doubleresult=1.0;

ifn==0

return1.0;

while(n>

1&

n<

170)

result=n--;

returnresult;

InputN:

\n\n%d!

=%lf\n"

n,fun(n));

3.程序设计题

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

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

合并的方式是:

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

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

voidfun(inta,intb,long*c)

inta,b;

longc;

FILE*out;

Inputa,b:

%d%d"

a,&

b);

fun(a,b,&

c);

Theresultis:

%ld\n"

c);

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

out=fopen("

fun(a+11,b+22,&

fprintf(out,"

fclose(out);

1.程序填空题

(1)n%100!

=0或n%100

(2)n%400==0(3)flag

(1)错误:

ifn==0正确:

if(n==0)

result=n--;

result*=n--;

voidfun(inta,intb,long*c)

*c=(a%10)*1000+(b%10)*100+(a/10)*10+b/10;

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

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2