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

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

来源:网络收集 时间:2026-08-24
导读: 三. 分析程序,写出运行结果。(每题4分,共20分) 1. 源程序如下,运行时假定键盘输入字符串为``2004`` #include void main(void) { int n=0; char c; while( (c=getchar( )) ! =`\\n` ) /*字符型数字*/ { if (c

三. 分析程序,写出运行结果。(每题4分,共20分) 1. 源程序如下,运行时假定键盘输入字符串为``2004``

#include

void main(void) {

int n=0; char c;

while( (c=getchar( )) ! =`\\n` ) /*字符型数字*/ {

if (c>=`0`&&c<=`9` )

n = n*10 + c- `0` ; /*数字*/ }

printf(“value=%d|n” ,n); }

结果为: value=2004 。 2. 源程序如下:

#include

void main(void) {

int num[9]={399,398,397,396,395,299,290,311,301}; int score[9]={81,85,59,77,90,66,89,93,73}; int iMax,iPos,i;

iPos=0;

iMax=score[iPos]; for(i=1;i<9;i++) if(score>iMax)

{

iPos=i;

iMax=score[iPox];

}

printf(“num=%d,score=%d”,num[iPos];score[iPos]);

结果为: num=311, score=93 。

3. 源程序如下,运行时假定键盘输入数据为:1 2 3 4 5 6 7 8 9 10 #include

void main(void) {

int i,a[10]; int *p;

p=a;

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

scanf(“%d“,p++); for(p=a;p< SPAN>;p++) if (*p%2)printf(“=”,*p);

}

结果为: 1 3 5 7 9 。

4. 源程序如下,两次运行,分别输入数据13和21 #include #include void main(void) {

int n,s;

scant (“%d”,&n); s=panduan( n);

if(s==1)printf(“yes\\n”); else printf(“no\\n); }

int panduan(int n) {

int k,j;

k=(int)sqrt((double)n); for(j=2;j<=k,j++)

{

if(n%j==0) break; }

if(j>k) retum(1); else retum(0); }

结果为 yes no

5.源程序如下,运行时假定键盘输入字符为:AxByCz #include #include

void main(void) {

char str[80]; int i; gets(str);

for(i=0;str!=`\\0`;i++)

if(str>=`a`&&str<=`z`) str-=32;

else if (str>=`A`&&str<=`Z`) str+=32; puts(str);

}

结果为: aXbYcZ 。

四. 下列程序中每个划线处有一个错误,改正划线中的错误,使其实现题目

c语言期末考试题及其答案(8).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)