教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 学前教育 >

c语言期末考试题及其答案(9)

来源:网络收集 时间:2026-08-24
导读: 要求。(每体4分,共20分) 1. 求 s=1+2+3+、、、、、、、+100 include 改正为_________________________。 void sum (void) 改正为_________________________。 { int s,i; for (s=0,i=1;i { s=s+ i ++; 改

要求。(每体4分,共20分)

1. 求 s=1+2+3+、、、、、、、+100

include 改正为_________________________。

void sum (void) 改正为_________________________。 {

int s,i;

for (s=0,i=1;i<=100;i++)

{

s=s+ i ++; 改正为__________________________。

}

printf (“s=%f”,s) 改正为__________________________。 }

2. 源程序实现求x

#include

double pow(float . int) 改正为_________________________。 void main(void) {

int i, n; float x;

scanf (“%f,%d”,&x,&n);

for (i=1; i<9;i++)

printf(“%d,%e\\n”, i, pow(i,x);

} 改正为______________________。 double v v pow(float x, int n)

{ int i;

double p=0; 改正为______________________。

for (i=1; i< i++)>改正为_______________________。

p*=x; retum(p); }

3. 源程序实现排升序。 #include

void main(void) {

int i, j, iMin, a[10]={4,3,5,1,10,12,2,6,7,9}, iTemp; for (i=0; i<9; i++)

{

iMin=0; 改正为_______________________。

for (j=i+1; j<10;j++)

if(a[iMin]< iMin=\改正为_______________________。

if (iMin==i) 改正为_________________________。 { iTemp=a;

a[iMin]=a; 改正为_________________________。 a[iMin]=iTemp; } }

for(i=0; i<10; i++) printf(“M”, a): }

4. 源程序为求平均值。 #include

void main(void) {

int i, sum; 改正为____________________。 float avg;

int sc[10], *p=sc;

for (i=0, i<10; i++) 改正为____________________。 {

scanf(“%d”, p++);

sum+= *p; 改正为____________________。 }

avg = sum/ 10; 改正为___________________。 printf(“avg=%f”, avg); }

5. 源程序求 eX=1+x+x2/2!+??+xn/n!前n+1项之和 #include void main(void> {

float exp , x , t;

int i, n;

scanf(“%f, %d”,&x, &n);

t=0; 改正为___________________。 exp=1.0;

for(i=1 ; i<=n; i++) {

if(t<1e-6) loop; 改正为__________________。 t+=x/i; 改正为___________________。 exp*=t; 改正为___________________。 }

printf(“\\n.6f”, exp);

}

五. 编程题 (每题6分,共30分)

1.根据以下程序框架,编写子函数,实现交换两个整型变量x和y的值。

#include

void swap (int *, int *); void main (void) {

int x, y;

scanf(“%d, %d”, &x, &y); swap( &x, &y); printf(“%d, %d”, x, y); }

void swap( ) { }

2.设某班人数36人,参加C语言考试,用一维数组score[36]存放考试成绩,已给出一部分程序,完善以下程序,使其实现统计并输出不及格人数及百分比。 #include

void main (void) { int i;

float scoer[36], precent; int count=0; for (i=0; i<36; i++) {

scanf(“%f”, &score);

}

3.完善以下程序使其实现由键盘任意输入一串字符,统计其中大写字母个数iA、小写字母个数ia、其他字符个数iother。 #include #include

void main (void) {

char str [80];

int i, iA=0, ia=0, iother=0;

}

4.完善以下程序使其实现求方阵主和辅对角线元素之和及其转置矩阵,设方阵用二维数组a表示,转置矩阵用t表示,sl和s2表示主和辅对角线元素之和。 #include

void main(void) {

int a[3] [3]={1,3,5,7,9,11,13,15,11};

int i, j, s1, s2;

int t[3] [3];

printf(“%d, %d,\\n”,s1, s2); for(i=0; i<3; i++) for(j=0; j<3; j++)

printf(“=”, t [j]); }

5.已知字符数组str[80],编写返回指针的子函数,实现在其中查找字符ch首次出现的位置。 #include #include

#include

char *lstrchar(char*, char); void main(void) {

char c, *p, str[80]; gets (str);

scanf(“%c”, &c); p=lstrchar(str,c);

if(p==NULL) printf(“char %c not found\\n”c); else printf(“The position is %d”, p-str); char “lstrchar( ) { }

…… 此处隐藏:450字,全部文档内容请下载后查看。喜欢就下载吧 ……
c语言期末考试题及其答案(9).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/595679.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)