大一c语言期末试题及参考答案Word文档格式.docx

上传人:b****4 文档编号:8298249 上传时间:2023-05-10 格式:DOCX 页数:16 大小:20.89KB
下载 相关 举报
大一c语言期末试题及参考答案Word文档格式.docx_第1页
第1页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第2页
第2页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第3页
第3页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第4页
第4页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第5页
第5页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第6页
第6页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第7页
第7页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第8页
第8页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第9页
第9页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第10页
第10页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第11页
第11页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第12页
第12页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第13页
第13页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第14页
第14页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第15页
第15页 / 共16页
大一c语言期末试题及参考答案Word文档格式.docx_第16页
第16页 / 共16页
亲,该文档总共16页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

大一c语言期末试题及参考答案Word文档格式.docx

《大一c语言期末试题及参考答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《大一c语言期末试题及参考答案Word文档格式.docx(16页珍藏版)》请在冰点文库上搜索。

大一c语言期末试题及参考答案Word文档格式.docx

floatcalculate(floatx,floaty,float*sub);

添加函数原型声明

main()

{

floata,b;

floatadd_reasult,sub_result;

scanf(“%f,%f”,a,b);

add_result=calculate(a,b,&

sub_result);

printf(“a*a+b*b=%d,a*a-b*b=%d\n”,add_result,sub_result);

}

floatcalculate(floatx,floaty,float*sub)添加函数类型

float*temp;

应该直接定义为变量floattemp;

sub=a*a-b*b;

*sub=a*a-b*b;

temp=a*a+b*b;

return*temp;

returntemp

(2)统计N个字符中大写字母和数字字符的个数

#include<

#defineN5

Count(char*str,int*result);

添加函数声明

main()

{

charstring[N][80];

chari;

intCapital_Count=0,Num_Count=0;

需要初始化为0

for(i=0;

i<

N;

i++)

scanf(“%s”,&

string[i]);

去掉&

for(I=0;

I<

I++)

Capital_Count+=Count(string[I],&

Num_Count);

Printf(“Capitalcount:

=%d,numbercount=%d\n”

Capital_Count,Num_Count);

Count(char*str,int*result)

inttemp,I;

inttemp=0,i;

temp应该初始化为0

for(I=0;

80;

If(str[I]>

=’A’&

str[I]<

=’Z’)

Temp++;

’0’||str[I]<

’9’)

*result++;

returntemp;

}

四程序填空10分

(答案参考书中p85~86)

(1)利用公式sinx=x-x

/3!

+x

x=0.5,n=20

#include<

main()

floaty,s,x,d,t;

intn,I,j;

scanf(“%d%f”,&

n,&

x);

s=1.0;

____________________________;

for(I=2;

n;

d=t=__________________________;

for(j=1;

_______________;

j++)

d=________________;

t=________________;

s=(-1)*s;

y+=_____________________;

(2)利用库函数char*strstr(char*sl,char*s2)在给定字符串中查找子串最后(最右)一次出现的位置。

如果S2并没有出现在S1的任何地方,函数返回一个NULL

指针。

如果第二个参数是一个空字符串,函数就返回S1;

注:

库函数charstrstr(char*s1,char*s2),这个函数在S1中查找子字符串S2第一次出现的起始位置,并返回一个指向该位置的指针。

如果S2并没有出现在S1的任何地方,函数返回一个NULL指针。

如果第二个参数是一个空字符串,函数返回S1;

(答案见书中p196~197)

string.h>

voidmain(void)

charstr[80]=”ABCdabcdfgabc”;

char*p;

p=my_strrstr(str,”abc”);

printf(“%s\n”,p);

p=my_strrstr(str,”“);

printf(“%s\n”,p);

char*my_strrstr(char*s1,char*s2)

char*last;

char*current;

_________________________;

if(________________________)

last=current=_____________;

While(______);

last=current;

current=_______;

returnlast;

五.写输出结果(20分)

(1)

voidfun(int*,int);

voidmain()

inta[]={5,6,7,8},i;

fun(a,4);

4;

printf("

%d\n"

a[i]);

voidfun(int*b,intn)

inti;

b[i]=i*2;

return;

}

2

4

6

(2)

inti,j,max;

introw=0,column=0;

inta[3][3]={{1,2,3},{2,-3,4},{9,4,7}};

max=a[0][0];

3;

for(j=0;

j<

{

if(a[i][j]>

max)

{

max=a[i][j];

row=i+1;

column=j+1;

}

}

printf("

max=%d,row=%d,column=%d\n"

max,row,column);

(书中例题5.5,p123)

max=9,row=3,column=1

(3)

intn=1;

voidfunc();

staticintx=5;

inty;

y=n;

main:

x=%d,y=%d,n=%d\n"

x,y,n);

func();

voidfunc()

staticintx=4;

inty=10;

x=x+2;

n=n+2;

y=y+n;

func:

x=5,y=1,n=1

x=6,y=13,n=3

x=5,y=1,n=3

(4)

structperson

charname[20];

intcount;

};

structpersonleader[3]={{"

li"

0},{"

zhang"

wang"

0}};

charname[20],m,n;

for(m=1;

m<

7;

m++)

scanf("

%s"

name);

for(n=0;

n<

n++)

if(!

strcmp(name,leader[n].name))

leader[n].count++;

break;

\n"

);

for(m=0;

m<

%s:

leader[m].name,leader[m].count);

当程序运行时,键入情况如下:

Li

Wang

Lei

Zhang

写出程序的输出结果。

(基本上是书中例题)

Li:

Zhang:

1

Wang:

(5)

char*name[]={"

capital"

"

index"

large"

small"

inta,b,n=4;

char*temp;

for(a=0;

a<

n-1;

a++)

for(b=a+1;

b<

b++)

if(strcmp(name[a],name[b])>

0)

temp=name[a];

name[a]=name[b];

name[b]=temp;

}在此之前是书中的例题7.19

%s\n"

name[a]+a);

输出时应该能够识别指针及偏移情况

capital

ndex

rge

ll

六、编写程序(35分)

(1)求一元二次方程ax

+bx+c=0的根,实系数a,b,c从终端输入,只考虑两个不同实根和两个相同的实根(9分)

(书中例题3.4,p66`67)

math.h>

floata,b,c;

floatx1,x2;

floatx3,x4;

floatm;

inputthenumbers:

a,b,c"

scanf("

%f%f%f"

&

a,&

b,&

c);

if(a==0)

theinputiserror!

return;

m=b*b-4*a*c;

if(m>

x1=(-b+sqrt(m))/(2*a);

x2=(-b-sqrt(m))/(2*a);

x1:

%.2fx2:

%.2f\n"

x1,x2);

elseif(m==0)

x1=x2=(-b+sqrt(m))/(2*a);

x1=x2=%.2f\n"

x1);

else

x3=-b/(2*a);

x4=sqrt(m)/(2*a);

x1=%.2f+%.2fi\n"

x3,x4);

x2=%.2f-%.2fi\n"

(2)编写一个函数,求s=a+aa+aaa+--------+aaaaaaaaa-----a,其中a是一个数字,例如2+22+222+2222(此时n=4)。

主函数a和n的输入,调用所函数和输出所求的累加和;

编写的函数完成计算。

(9分)

注意:

不得使用全局变量,注意程序结构

(书中习题3:

4。

16)

longCal(longa,longn);

longsn=0;

longa,n;

pleaseinputan:

"

%d%d"

n);

sn=Cal(a,n);

a+aa+aaa+...+aa...a=%ld\n\n"

sn);

longintCal(longa,longn)

longsn=0,m=0;

m=m*10+a;

sn+=m;

returnsn;

(3)从十个字符串中找出所要的某个字符串,若能找到则把他删除,然后输出新字符串;

若未找到则输出“”cannotfond”.(9分)

chars[10][80];

chars2[80];

inti,j;

intnum=0;

pleaseenter10string:

10;

gets(s[i]);

pleaseenters2string:

gets(s2);

if(strcmp(s[i],s2)==0)

for(j=i;

9-num;

strcpy(s[j],s[j+1]);

i--;

num++;

10-num;

puts(s[i]);

(4)一个班有N个同学,修5门课从键盘输入他们的性名、学号、性别和成绩。

1)按平均成绩从高到底打印全班的成绩单。

2)求第三门课的平均分

3)找出平均分在90以上或全部功课在85以上的女生。

要求:

输入、输出、计算、排序和查找分别用函数实现,主函数只是调用这些函数。

不得使用全局变量。

#defineN5

structStudent

intnumber;

intsex;

floatscore[5];

floataver;

voidInput(structStudent*stu);

voidAverage(structStudent*stu,float*aver);

voidSort(structStudent*stu);

voidSearch(structStudent*stu,floatscore);

structStudentstu[N];

floatscore=85.0;

floataver3;

Input(stu);

Sort(stu);

Average(stu,&

aver3);

average3is%.2f\n"

aver3);

Search(stu,score);

voidInput(structStudent*stu)

floataver=0;

aver=0;

pleaseentername:

gets(stu[i].name);

pleaseenternumbersex:

stu[i].number,&

stu[i].sex);

pleaseenterscore(5):

5;

scanf("

%f"

stu[i].score[j]);

aver+=stu[i].score[j];

stu[i].aver=aver/5;

getchar();

voidSort(structStudent*stu)

structStudenttemp;

N-1;

for(j=i+1;

if(stu[i].aver<

stu[j].aver)

temp=stu[i];

stu[i]=stu[j];

stu[j]=temp;

NameNumbSexscore(5)aver\n"

%8s%d%d%.2f%.2f%.2f%.2f%.2f%.2f\n"

stu[i].name,

stu[i].number,

stu[i].sex,

stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].score[3],stu[i].score[4],

stu[i].aver);

voidAverage(structStudent*stu,float*average3)

floatsum3=0;

sum3+=stu[i].score[2];

*average3=sum3/N;

voidSearch(structStudent*stu,floatscore)

intflag=1;

\naver>

90score>

85\n"

flag=flag&

(stu[i].score[j]>

score);

if(stu[i].aver>

90.0&

flag)

printf("

\n\n"

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

当前位置:首页 > 自然科学 > 化学

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

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