福建省高等学校计算机等级考试二级C语言 编程题.docx

上传人:b****6 文档编号:9167893 上传时间:2023-02-03 格式:DOCX 页数:13 大小:27.53KB
下载 相关 举报
福建省高等学校计算机等级考试二级C语言 编程题.docx_第1页
第1页 / 共13页
福建省高等学校计算机等级考试二级C语言 编程题.docx_第2页
第2页 / 共13页
福建省高等学校计算机等级考试二级C语言 编程题.docx_第3页
第3页 / 共13页
福建省高等学校计算机等级考试二级C语言 编程题.docx_第4页
第4页 / 共13页
福建省高等学校计算机等级考试二级C语言 编程题.docx_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

福建省高等学校计算机等级考试二级C语言 编程题.docx

《福建省高等学校计算机等级考试二级C语言 编程题.docx》由会员分享,可在线阅读,更多相关《福建省高等学校计算机等级考试二级C语言 编程题.docx(13页珍藏版)》请在冰豆网上搜索。

福建省高等学校计算机等级考试二级C语言 编程题.docx

福建省高等学校计算机等级考试二级C语言编程题

11.打开考生文件夹中的Cprog011.C,完成其中的函数fun1,该函数的数学表达式是:

例如:

fun1(0.76)=2.175

fun1(3.00)=5.307

fun1(3.76)=9.111

#include

#include

doublefun1(doublex)

{/**/

doublef;

f=(1+sin(x)+exp(x))/(1+x);

returnf;

/**/

}

voidmain()

{

clrscr();

printf("fun1(0.76)=%8.3lf\n",fun1(0.76));

printf("fun1(3.00)=%8.3lf\n",fun1(3.00));

printf("fun1(3.76)=%8.3lf\n",fun1(3.76));

}

12.打开考生文件夹中的Cprog012.C,完成其中的函数fun2(inta[],intn,intb[],intc[]),实现:

1)将数组a中大于-20的元素依次存放在数组b中;

2)将数组b中的元素按照从小到大的顺序依次存放到数组c中;

3)函数返回数组b中的元素个数。

#include

#include

#include

#include

intfun2(inta[],intn,intb[],intc[])

{/**/

intnb=0;

inti,j=0,temp;

for(i=0;i

if(a[i]>-20){b[j]=a[i];nb++;j++;}

for(i=0;i

for(i=0;i

for(j=0;j

if(c[j]>c[j+1])

{

temp=c[j];

c[j]=c[j+1];

c[j+1]=temp;

}

returnnb;

/**/}

voidmain()

{intn=10,i,nb;

intaa[10]={12,-10,-31,-18,-15,50,17,15,-20,20};

intbb[10],cc[10];

clrscr();

printf("Thereare%2delementsinaa.\n",n);

printf("Theyare:

");

for(i=0;i

printf("\n");

nb=fun2(aa,n,bb,cc);

printf("Elementsinbbare:

");

for(i=0;i

printf("\n");

printf("Elementsinccare:

");

for(i=0;i

printf("\n");

printf("Thereare%2delementsinbb.\n",nb);

}

21.打开考生文件夹中的Cprog021.C,完成其中的函数fun1,该函数的数学表达式使:

例如:

fun1(0.76)=3.582

fun1(3.00)=5.369

fun(3.76)=8.931

#include

#include

doublefun1(doublex)

{/**/

doublef;

f=(exp(x)+fabs(x-6))/(x+1.3);

returnf;

/**/

}

voidmain()

{

clrscr();

printf("fun1(0.76)=%8.3lf\n",fun1(0.76));

printf("fun1(3.00)=%8.3lf\n",fun1(3.00));

printf("fun1(3.76)=%8.3lf\n",fun1(3.76));

}

22.打开考生文件夹中的Cprog022.C,完成其中的函数fun2(chara[],charb[],charc[]),实现:

将三个字符串a、b、c从小到大排序后输出。

注意:

字符串比较函数为strcmp(str1,str2),

字符串赋值函数为strcpy(str1,str2)。

#include

#include

#include

#include

voidfun2(chara[],charb[],charc[])

{

/**/

chartemp[15];

if(strcmp(a,b)>0){strcpy(temp,a);strcpy(a,b);strcpy(b,temp);}

if(strcmp(a,c)>0){strcpy(temp,a);strcpy(a,c);strcpy(c,temp);}

if(strcmp(b,c)>0){strcpy(temp,b);strcpy(b,c);strcpy(c,temp);}

/**/

}

voidmain()

{charstr1[15]="Fuzhou",str2[15]="Fujian",str3[15]="China";

clrscr();

fun2(str1,str2,str3);

printf("Theorderedstringsis:

%s,%s,%s\n",str1,str2,str3);

getch();

}

31.打开cprog031.c完成其中的函数fun1,该函数的数学表达式是:

1.2当x<3时

fun1(x)=10当x=3时

2x+1当x>3时

例如:

fun1(0.76)=1.200

fun1(3.00)=10.000

fun1(3.76)=8.520

#include

#include

doublefun1(doublex)

{

/**/

doublef;

if(x<3)f=1.2;

elseif(x==3)f=10;

elsef=2*x+1;

returnf;

/**/

}

voidmain()

{

clrscr();

printf("fun1(0.76)=%8.3lf\n",fun1(0.76));

printf("fun1(3.00)=%8.3lf\n",fun1(3.00));

printf("fun1(3.76)=%8.3lf\n",fun1(3.76));

}

32.打开cprog032.c完成其中的函数fun(char*s),使程序实现统计输入字符串中空格的个数。

#include

intfun(char*s)

{/**/

inti,n=0;

for(i=0;s[i]!

='\0';i++)

if(s[i]=='')n++;

returnn;

/**/

}

voidmain()

{

charstr[255];

gets(str);

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

}

41.打开程序Cprog041.C,完成其中的f()函数,使其计算:

如输入:

12输出:

f(12.000)=10.387

输入:

32.25输出:

f(32.250)=12.935

输入:

0.113输出:

f(0.113)=1.568

#include

#include

doublef(floatx)

{

/**/

doublef;

if(x<=0)f=0;

elsef=(fabs(x)+3.2)/(sin(x)+2);

returnf;

/**/

}

voidmain()

{

floatx;

doubley;

printf("Pleaseinputanumber:

\n");

scanf("%f",&x);

y=f(x);

printf("f(%.3f)=%.3f\n",x,y);

getch();

}

42.打开程序Cprog042.C,完成其中的fun()函数,使函数打印出Fibonacci数列的前20个数。

该数列(1,1,2,3,5,8,13,…)的第1、第2个数为1,从第3个数开始每个数等于前2个数之和。

#include

#include

voidfun(inta[],intm)

{

/**/

inti;

a[0]=a[1]=1;

for(i=2;i<20;i++)

a[i]=a[i-1]+a[i-2];

/**/

}

voidmain()

{

inta[20],i;

fun(a,20);

for(i=0;i<20;i++)

printf("%d",a[i]);

printf("\n");

getch();

}

51.打开程序Cprog051.C,完成其中的f()函数,使其计算:

如输入:

0.4输出:

f(0.40)=0.82

输入:

1.5输出:

f(1.50)=1.24

输入:

780输出:

f(780.00)=-1.00

#include

#include

doublef(floatx)

{

/**/

doublef;

if(fabs(x)<700)f=(sqrt(5.8+fabs(x)))/(cos(x)+2.1);

elsef=-1.0;

returnf;

/**/

}

voidmain()

{

floatx;

doubley;

printf("Pleaseinputanumber:

\n");

scanf("%f",&x);

y=f(x);

printf("f(%0.2f)=%0.2f\n",x,y);

getch();

}

52.打开程序Cprog052.C,完成其中的fun()函数,使其判断一个矩阵是否为对称矩阵,若矩阵对称返回1,不对称返回0。

说明:

矩阵a使一个二维数组,若其中的第k行第j列的元素与第j行第k列的元素相同,则称其为对称矩阵,否则为非对称矩阵。

如输入:

6312如输入:

6912

31883188

128734822

输出:

Yes输出:

No

#include

#include

intfun(inta[][3],intm)

{

/**/

intb=1;

inti,j;

for(i=0;i

{

for(j=0;j

=a[j][i]){b=0;break;}}

if(b==0)break;

}

returnb;

/**/

}

voidmain()

{

inta[3][3],i,j;

intb;

fun(a,20);

for(i=0;i<3;i++)

for(j=0;j<3;j++)

scanf("%d",&a[i][j]);

b=fun(a,3);

if(b==1)

printf("Yes\n");

else

printf("No\n");

getch();

}

61.打开程序Cprog061.C,完成其中的f()函数,使其计算:

如:

输入:

0.8输出:

f(0.80)=0.96

输入:

4.5输出:

f(4.50)=107.05

输入:

725输出:

f(725.00)=-1.00

#include

#include

doublef(floatx)

{

/**/

doublef;

if(fabs(x)<300)f=pow(x,3)/log10(fabs(x)+2.6);

elsef=-1.0;

returnf;

/**/

}

voidmain()

{

floatx;

doubley;

printf("Pleaseinputanumber:

\n");

scanf("%f",&x);

y=f(x);

printf("f(%0.2f)=%0.2f\n",x,y);

getch();

}

62.打开程序Cprog062.C,完成其中的fun()函数,使其实现四则运算的功能。

如:

输入:

3.22.1

输出:

3.20+2.10=5.3

3.2-2.10=1.10

3.20*2.10=6.72

3.20/2.10=1.52

#include

#include

floatfun(floata,charflag,floatb)

{

/**/

floatf;

switch(flag)

{

case‘+’:

f=a+b;break;

case‘-’:

f=a-b;break;

case‘*’:

f=a*b;break;

case‘/’:

f=a/b;break;

}

returnf;

/**/

}

voidmain()

{

floata,b;

printf("Pleaseinputtwonumbers:

\n");

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

printf("%.2f+%.2f=%.2f\n",a,b,fun(a,'+',b));

printf("%.2f-%.2f=%.2f\n",a,b,fun(a,'-',b));

printf("%.2f*%.2f=%.2f\n",a,b,fun(a,'*',b));

printf("%.2f/%.2f=%.2f\n",a,b,fun(a,'/',b));

getch();

}

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

当前位置:首页 > 工作范文 > 行政公文

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

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