大一c语言期末试题及参考答案_第1页
大一c语言期末试题及参考答案_第2页
大一c语言期末试题及参考答案_第3页
大一c语言期末试题及参考答案_第4页
大一c语言期末试题及参考答案_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

千里之行,始于足下让知识带有温度。第第2页/共2页精品文档推荐大一c语言期末试题及参考答案2022级信息学院《C语言设计》考试试题

一、推断下列语句或程序的对错。10分√

1intx=y=z=’0’;(×)y,z没有定义

2#include;(×)不能有分号,#开始的结尾均不能有分号;

3printf(“%s\n”,”clanguage”);(√)

4floata[100];

int*p=a;(×)数据类型不匹配

5charstr[20];

6intdata[4]={0,1,2,3,4};(×)五个元素,但是惟独四个单元

7floatx=1.45e+310L;(×)数值越界

8intxyz-1=2;(×)

9intx=‘\xae’;(√)

10int*p,a[2][3];

p=a;(×)数据类型不匹配

二计算下列表达式的值10分

设unsignedinta=10,b=17,c=5,d=3;

floatf;

(1)f=b/c(3.0)

(2)!(a+b)+c-1添加函数原型声明

main()

{

floata,b;

floatadd_reasult,sub_result;

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

add_result=calculate(a,b,应当直接定义为变量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=’A’

If(str[I]>’0’||str[I]main()

{

floaty,s,x,d,t;

intn,I,j;

scanf(“%d%f”,

s=1.0;

____________________________;

for(I=2;I

#include

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)

#include

voidfun(int*,int);

voidmain()

{

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

fun(a,4);

for(i=0;i

voidmain()

{

inti,j,max;

introw=0,column=0;

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

max=a[0][0];

for(i=0;imax)

{

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)

#include

intn=1;

voidfunc();

voidmain()

{

staticintx=5;

inty;

y=n;

printf("main:x=%d,y=%d,n=%d\n",x,y,n);

func();

printf("main:x=%d,y=%d,n=%d\n",x,y,n);

}

voidfunc()

{

staticintx=4;

inty=10;

x=x+2;

n=n+2;

y=y+n;

printf("func:x=%d,y=%d,n=%d\n",x,y,n);

}

main:x=5,y=1,n=1

func:x=6,y=13,n=3

main:x=5,y=1,n=3

(4)

#include

#include

structperson

{

charname[20];

intcount;

};

voidmain()

{

structpersonleader[3]={{"li",0},{"zhang",0},{"wang",0}};

charname[20],m,n;

for(m=1;m

#include

voidmain()

{

char*name[]={"capital","index","large","small"};

inta,b,n=4;

char*temp;

for(a=0;a0)

{

temp=name[a];

name[a]=name[b];

name[b]=temp;

}

}在此之前是书中的例题7.19for(a=0;a

#include

voidmain()

{

floata,b,c;

floatx1,x2;

floatx3,x4;

floatm;

printf("inputthenumbers:a,b,c");

scanf("%f%f%f",

if(a==0)

{

printf("theinputiserror!\n");

return;

}

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

if(m>0)

{

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

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

printf("x1:%.2fx2:%.2f\n",x1,x2);

}

elseif(m==0)

{

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

printf("x1=x2=%.2f\n",x1);

}

else

{

x3=-b/(2*a);

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

printf("x1=%.2f+%.2fi\n",x3,x4);

printf("x2=%.2f-%.2fi\n",x3,x4);

}

}

(2)编写一个函数,求s=a+aa+aaa++aaaaaaaaaa,其中a是一个数字,例如2+22+222+2222(此时n=4)。主函数a和n的输入,调用所函数和输出所求的累加和;编写的函数完成计算。(9分)

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

(书中习题3:4。16)

#include

#include

longCal(longa,longn);

main()

{

longsn=0;

longa,n;

printf("pleaseinputan:");

scanf("%d%d",

sn=Cal(a,n);

printf("a+aa+aaa+...+aa...a=%ld\n\n",sn);

}

longintCal(longa,longn)

{

inti;

longsn=0,m=0;

for(i=0;i

#include

main()

{

chars[10][80];

chars2[80];

inti,j;

intnum=0;

printf("pleaseenter10string:\n");

for(i=0;i

#defineN5

structStudent

{

charname[20];

intnumber;

intsex;

floatscore[5];

floataver;

};

voidInput(structStudent*stu);

voidAverage(structStudent*stu,float*aver);

voidSort(structStudent*stu);

voidSearch(structStudent*stu,floatscore);

main()

{

structStudentstu[N];

floatscore=85.0;

floataver3;

Input(stu);

Sort(stu);

Average(stu,

printf("average3is%.2f\n",aver3);

Search(stu,score);

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论