上机考试题库80题答案.pdf





《上机考试题库80题答案.pdf》由会员分享,可在线阅读,更多相关《上机考试题库80题答案.pdf(58页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、第 1套main()if(i+l)%IO=O)是:将字符串str中的小写字母都改一、填空题 f printf(out,%4d n,.ai);为对应的大写字母,其它字符不变。给定程序的功能是求1/4的圆周长。long m;e lse例 如,若 输 入“a s A S”,则输出函数通过形参得到圆的直径,函数printf(nple ase e nte r a numbe r:):f printf(out,%4d,a(i);“A SA S”。返 回1/4的圆周长(圆周长公式为:sc anf(%ld,&m);f c losc(out);请修改程序中的错误,使它能统计L=n d,在程序中定义的变量名要与p
2、rintf(n%ld n,f un(m):出正确的结果。公式的变量相同)。)注意:不要改动m a i n函数,不能增例如:输入圆的直径值:19.527,第2套行或删行,也不能更改程序的结构输出为:15.336457三、编程题一、填空题#inc lud c 请勿改动主函数m a i n与其他函数请 编 写 个 曲 数f un,它的功能是:函数f u n的功能是:统计长整数te st#inc lud e 中的任何内容,仅在横线上填写所求 出1到m之内(含m)能被7或11的各位上出现数字5、6、7的次数,#inc lud c 需的若表达式或语句。整初的所有整数放在数组b中,通并 通 过 外 部(全
3、局)变 后s u m 5、c h ar*f un(c h ar strJ)#inc lud e 过n返回这些数的个数。sum6,s u m 7返回主函数。d ouble f unf d ouble d)例如,若传送给m的值 为2 0,则例如:te st=8943l67 6 Ht,结果应int i;程庠输出7 11 14c该为:suin5=0 sum6=2 s u m 7=】。f or(i=0;sir(i;i+)re turn 3.14159*d/4.0;请勿改动主函数m a i n与其他函数请勿改动工函数m a i n与其它函数if(str(i=a,&-str(i=z)中的任何内容,仅在函数f
4、 u n的花中的任何内容,仅 在f u n函数的横str 卜=32;main()括号中填入所编写的若干语句。线上填写所需的若干表达式或语re turn(str);(#i nc 1 ud c 句。d ouble z;#inc lud e#inc lud e main()printf(Input th e d of th e round:);#d c f inc N 10()ini sum5.sum6.sum7;(sc anf(H%ir,&z);void f un(int m,int*b,int*n)void f und ong te st)c h ar str8l;prinif CL=%lf n
5、,f un(z);printf(nple ase e nte r a string:);)int ij=O;*n=O;sum5=sum6=sum7=0;ge ts(str);f or(i=l;i=m;i+)wh ile(te st)printf(nTh e re sult string二、改错题if(i%7=0lli%ll=0)Iis:n%s,f un(str);下列给定程序中函数fu n的功能switc h(te s(%10)1是:计算正整数m的各位上的数字bUl=i:(三、编程题之积。例 如,若 输 入2 0 2,则输出j+:c ase 5:sum5+;bre ak;请 编 写 个 函 数
6、f u n,它的功能是:应该是0。1c ase 6:sum64-+:bre ak;找出一维整型数组元素中最小的值请修改程序中的错误,得出正确的*n=j:c ase 7:sum7+;和它所在的下标,最小的值和它所结果1在的下标通过形参传同。数组元素注意:不要改动m a i n函数,不能增main()ie st/=10;中的值已在主函数中哒予。行或删行,也不能更改程序的结构主函数中a是数组名,n是a中的#inc lud e int aN.n.i;数据个数,m i n存放城小值,f lag#inc lud e FILE*out;main()存放最小值所在元素的下标long f un(long n)f
7、 un(20.a.&n);请勿改动主函数m a i n与其它函数(f or(i=0;in;i+)long te st=8943167 6L;中的任何内容,仅在函数f u n的花long r=l;if(i+l)%20=0)f un(te st);括号中填入所编写的若干语句。d oprintf(%4d n,a(i);printf(nTh e c ount re sult:n);#inc lud e e lseprintf(ie st=%ld s u m 5=%d#inc lud e r*=n%IO;printf(%4d,ai);s u m 6=%d#inc lud e n/=10;prinlf(n
8、);sum7=%d n.te st.sum5.sum6.su m 7);void f un(int b.int n,int*min,int*d)wh ile(n);out=f ope n(outf ile.d at,w);)re tum(r);f un(IOO.a.&n);二、改错题in(i;)f or(i=0;in;i+)下列给定程序中,函 数f u n的功能*min=b|0|;*d=0:f or(i=0;in;i+)if(bi*min)(*min=b|i;*d=i;main()int i.a20,min.tlag.n=10:HLE*out;f or(i=0;in;i+)a(i|=rand(
9、)%50;printf(%4d,ai);Iprintf(n):f un(a.n.&inin.&nag);printf(min=%5d,Ind c x=%4d n.min.f lag);outsf ope nCoutf lie.d atVw);me mc pyCa.,3.1415926535897 9323846264338327 9:32);f un(a.8.&min,&nag);f printf(out.Kmin=%5d,Ind c x=%4d,inin.f lag);f c lose(out);1 9 70 4 5 23 8 3第3套上机考试试题一、填空题请补充m a i n函 数,该函数
10、的功能是:从键盘输入组整数,使用条件表达式找出最大的整数。当输入的整数为-1时结束。例如:输入96121 23 343 232 54 89 365 89-1 时,最大的数为365。s+;中的任何内容,仅在函数f u n的花仅在横线上填写所需的若干表达式括号中填入所编写的若干语句或语句,请勿改动函数中的其它住re turn n:#inc lud e 何内容#inc lud e#inc lud c main()#inc lud e#inc lud e(#d e f ine N 3#d c f i n c N U M 1(X)c h ar str6;d ouble f un(int bHN)main
11、()int i;1int n;ini i.j,k=O:int nNUM;print f(Ente r a string(oc tald ouble r=0.0;int i=-1;d igits):);f or(j=0;j5)r+=b0OJ;as e nd:n);k+:d oprintf(Error:string too1longe r!nnM);f or(j=OjN;j+)i+;c xit(O);(printf(n%d=,i);1r+=b|N-l|(jbsc anf(%d”,&n“);ior(i=0:str|i:i+)k+:M A X=M A X n(i?n i):M A Xif(stri7,
12、)1(f brf i=l;i=N-2;i+)wh ile(ni|!=-l);printf(Error:%c not is oc tal(prinlf CTh e M A X=%d nM.MAX);d igits!nn,str(i);r+=bi(O;)e xit(O);1k+;I二、改错题iprintf(Th e original string:);Jf or(i=l;i=N-2:i+)下列给定程序中,函数f u n的功能puts(str);(是:将一个由八进制数字字符组成n=f un(str);r+=bi(N-l;的字符卡转换为与我数值相等的十printf(n%s is c onvc rc d
13、 to intc gck+:进制整数。例 如,若 输 入Hill,numbe r:%d nn,str,n);)则输出将是4 6 8 1。)re turn r/=k;请修改程序中的错误,使它能得出)正确结果。三、编程题main()注意:不要改动m a i n函数,不能增下列程序定义了 NXN的二维数(行或册9行,也不能更改程序的结构组,并在主函数中赋值。请编写函int c(N(N=1.9,7.4,5.23.8.3):#inc lud e 数fu n,函数的功能是:求出数组int i,j;#inc lud e 周边元素的平均值并作为函数值FlLE*out;#inc)ud e 返回给主函数中的r.d
14、 ouble r;int f un(c h ar*s)例如:若c数组中的值为:printf(M*n);f or(i=();iN;i+)int n;(n=*s-O;f or(j=0;jN;j+)S+;(wh ile(*s!=O)则 返 回 主 程 序 后r的值应为printf(%4d,c IiU);4.625000)n=n*8+*s-O:请勿改动主函数m a i n与其他函数printf CnM);300,则函数值为2 6 4 6。括号中填入所编写的若干旃句。i n t j=0;r=f u n(c):请修改程序中的错误或在横线处填注意:部分源程序给出如卜”c h a r*p=s;p r i n
15、l f C T H E R E S U E H n );上适当的内容并把横线删除,使程#i n c l u d e w h i l e C p)p r i n t f C T h e r i s%lAnK,r);序能得出正确的结果。#i n c l u d e(u t=f o p c n(o u t f i i c.d a t ,w );注意:不要改动main函 数,不能增#i n c l u d c i f(*p=A&p=Z )f pr i n tf(o ut,%l f ,r):行或胴行,也不能更改程序的结构。vo i d f un(ch a r*s tr,ch a r s J)f cl o
16、 s c(o ut);#i n cl ud cs U l=*P;#i n cl ud e i n t i j=O,n;j+;i n t f un(i n t n)n=s tr l e n(s tr);第4套上机考试试题(f o r(i=0;i =2)&(m i x l 0)(sj i;将字符串市中的小写字母都改为s l jl=s l 币 1;对应的大写字母,其它字符不变。i f(n%l l=O)l l(n%1 9)=0)j+;m a i n()例如:若输入W e l c o m e叫程序输出(I(结果是“WEL COM E!”。m=m+n;向 他ch a r s tr 100;请勿改动主函数m
17、ain与其它函数m i x+;pr i n tf(M n P l ca s c In pul a s tr i n g:);中的任何内容,仅 在fu n函数的横)i n a i n()g e ts(s tr):线上填写所需的若干表达式或语n-;(pr i n tf(n n T h c o r i g i n a l s tr i n g句。)ch a r s tr(100,s 100;i s:%s n ,s tr);#i n cl ud cr e tur n m;F ILE*o ut:f un(s(r);#i n cl ud e pr i n tf(n pl e a s e e n te r
18、s tr i n g:);pr i n tf(M n n T h e s tr i n g o f ch a n g i n g#i n cl ud e m a i n()s ca n f(,%s .s tr);i s:%s n .s i r);ch a r*f un(ch a r s tr(J)f un(s tr,s);pr i n tf(%d n f un(300);pr i n tf(n T h e r e s ul t i s:%s n .s);二、改错题i n t j;)o ut=f o pe n(o utf i!e.d a t,w);下列给定程序中,函 数fu n的功能f o r(
19、j=0;s tr l j y+)s tr cpy(s tr.pl e a s e e n te r s tr i n g:);是:先从键盘上输入 个3行3列三、编程题f un(s tr,s);矩阵的各个元素的值,然后输出主i f(s tr l j =a)&(s tr|j =,z)请编写函数fu n,其功能 是:将s trf pr i n i f(o ut.%s ,s);对角线元素之和。s(r(j)-=32;所指字符串中除了下标为偶数、同f cl o s e(o ut);谙修改函数fu n中的错误或在横线1时ASCH值也为偶数的字符外,其)处填上适当的内容并把横线删除,r e tum(s tr)
20、;余的全部删除:串中剩余字符所形第5套上机考试试题得出正确结果。成的一个 新 串 放 在s所指的数组一、填空题注意:不要改动main函数,不能增m a i n()中。请补充f u n函数,该函数的功能是:行或删行,也不能更改程序的结构.例如,若 市所指字符串中的内容为依次取出字符串中所有大写字母,ch a r s tr f 100;ABCD EFG123456,形成新的字符串,并取代原字符串.#i n cl ud e pr i n i f(n pl e a s e e n te r a s tr i n g:);其中字符A的ASCH码值为奇数,例如,输 入s d f A S D s d.则输出
21、ASD 0vo i d f un()g e ts(s tr);因此 应 当 删 除;其 中 字 符B的请勿改动主函数main与其它函数(pr i n i f(n T h e r e s ul t s tr i n gASCI I值为偶数,但在数组中的下中的任何内容,仅 在fu n函数的横i n t a a 3(3J,s um;i s:n%sM,f un(s tr);标为奇数,因此也应当删除:而字线上填写所需的若干表达式或语i n t i.j;)符2的ASCH码值为偶数,所在数句。s um=0;二、改错题组中的下标也为偶数,因此不应当注意:部分源程序给出如下。f o r(i=0;i 3;i+)下
22、列给定程序中,函数fu n的功能删除,其它以此类推。爆 后s所指#i n cl ud e tb r(j=0;j 3y-H-)是:计 算 并 输 山n以 内最大的10的数组中的内容应是2 4 6。#i n cl ud e s ca n f(%d ,&a a|i)(j);个能被1 1或1 9整除的自然数之和。请勿改动主函数main与其它函数vo i d f un(ch a r*s)f o r(i=0;i 3u+)n的值由主函数传入,若n的值为中的任何内容,仅在函数fu n的花(s um=s um+a a i i ;printf(sum=%ln.sum):序对每5个元素求一个平均值,并)1f pri
23、 ntf(out,%d n%d je sult,store re s将这些值依次存放在r所指的数组printf(nnTh e re sult:n);inain()ullj);中。若1所指数组中元素的个数不f or(i=0;ij;i+)(f c lose(out):是5的倍数,多余部分忽略不计0printf(%6.2f.b(i);f un();例如,t所指数组有1 4个元素,则printf(nn);只对前1 0个元素进行处理,不对最第6套上机考试试题后的4个元素求平均值。三、编程题三、编程题一、填空题请修改程序中的错误,得出正确的请编写,个函 数void f un(int x.int请编写一个函
24、数void f un(int*s.inl给定程序的功能是判断字符*s中结果。sum.int se le c t),该函数的功能是:用来求出数组的最小元的某个字符是否与字符ch相同,若注意:不要改动m a i n函数,不能增将大于整数x且紧靠x的s u m个素素在数组中的下标,并存放在re sult相同什么也不做,若不同则插在字行或删行,也不能更改程序的结构。数存入se le c t所指的数组中。所指的存储单元中。符串的最后。例如,输 入te st,如#inc lud e 例如,输入:121 8,则应输出:例如,愉入如下整数:果输入e,输出的结果不变,但如#d e f ine N U M 201
25、27 131 137 139 149 151 157 163=564.165.567,121,948,324,果输入a,结果te sta。int f un(d ouble*t,d ouble*r)请勿改动主函数m a i n与其它函数329,454,5345,7 83,434,124.请勿改动主函数m a i n与其它函数中的任何内容,仅在函数f u n的花561.985.555中的任何内容,仅在横线上填写所int j.i;括号中填入所编写的若干语句。则输出结果为:3,121。需的若干表达式或语句。d ouble sum;注意:部分源程序给出如下。请勿改动主月数m a i n与其它函数注意:部
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 上机 考试 题库 80 答案

限制150内