还剩13页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
语言程序设计.江苏海洋大学中国大学课后章节答案期末考试C mooc题库年2023有以下关于语句程序
1.if-else#includestdio.h int main{int a=2,b=-ljc=2;ifab ifb0c=c-,2;else c=c+l;printf%d\n c;return0;}程序的运行结果是().答案2关于语句的程序
2.if#include stdio.h intmain{int a,b’s;scanf%d%cT,a,b;s=a;ifab s=b;s*=s;printf,,%d\n,\s;return0;}若执行以上程序时从键盘上输入和则输出结果是.34,答案以下程序输出的结果是()
19.#include stdio.h intmain{int num=0,s=0;whilenum3{rintf,,%d\n,\s;return0;}num++;s+=num;}p答案:6执行下面程序,输出结果是()
20.#include stdio.h intmain{int x3y;〈,forx=l,y=5;x y;x++y--;printf%d\n x;return0;}答案:执行下面程序,输出结果是()
21.#include stdio.h intmain{int i,sum=0;fori=0;i=3;sum+4-i++sum+=i;printfM%d\nnsum;return0;}答案:10要求下面的程序运行后,显示如下结果:
22.21046152324785132则程序中的划线处应填入.#include stdio.h intmain{int a
[4]
[4]={};int i,j;fori=0;i4;i++{forj=0;j4;j++printfn%4d\a[i][j];prin;;tf\n}return0}答案{2,1046},{152,3},{2,478},{5,132}定义如下变量和数组:
23.则下面语句的输出结果是int i;int x
[4]
[4]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};.fori=0;i4;i++printf n%3d\x[i][3-i];答案471013下面程序输出的结果是.
24.#include stdio.h intmain凯{int staticint6]={1,2,3,4,5,6};fori=0,j=l;i5;++i,j++x+=a[i]*a[j];printf n%d\n\x;ret;urn0}答案:数组中相邻各元素的乘积之和a以下程序输出的结果是()
25..#include stdio.h intmain{char str[]=,,la2b3c;int i;ifstr[i]=,0,str[i]=,9,i];fori=0;str[i]!=\0*;i++printfprintfCAn;return0;},1%c,,^str[答案:123有以下语句的程序:
3.if%#include stdio.h intmain{int y=-l3x;scanf cT,x;ifx!=0ifx0y=l;elsey=0;printf%d\n,y;return0;}当输入时,输出的结果是().5答案:有以下语句程序段:
4.for#include stdio.h intmain{int k’j’s;fork=l;k3;k++{s=l;forj=k;j4;j++s%+=j;}printf d\ns;return0;}程序段的输出结果是(].答案:以下关于语句程序
5.for#include stdio.h intmain%{int i‘j’ni=0;fori=l;i=15;i+=4m++;printf d\nm;return0;}程序段的输出结果是].答案4有以下关于语句的程序
6.do—while%#include stdio.h intmain{int x=5;do{printf”cT,x=3;}while!--x;return0;}程序的输出结果是.答案2有以下关于语句的程序
7.for#include stdio.h ftinclude math.h intmain{int sum=l;fori=l;i=3;i++sum+=powi,2;printf%drT’sum;return0;程序的输出结果是().答案:15有以下程序
8.#includestdio.h intmain{int x,i;fori=l;i=30;i++{x=i;ifx%2==0ifx%3==0ifx%4==0printfH%d,x;}printfXn;return0;}程序的输出结果是.答案1224有以下程序:
9.#includestdio.h intmain{int a=0,b=l,c=2;ifab ifb0c=0;else c+=1;printf,,%d\n,\c;return0;}执行后输出的结果是()・答案:3有以下语句的程序
10.if#includestdio.h intmain{int a=1^b=2jc=l;ifab ifb0c=c-1;else c=c+2;printf,,%d\n,,c;return0;}执行后输出的结果是.答案0有以下关于语句的程序
11.breakftinclude stdio.h intmain;{int i;fori=l;i=5;i++{if!i%3printf*else break;printfH#H;}printfover!\nH;return0;}程序输出的结果是.答案over!以下程序是实现输出的值
12.Sn・其中是一个正整数,表示的位数,Sn=a+aa+aaa+aaaa+..+aaa..a a n a其中,和的值由键盘输入an如输入2,5则Sn=2+22+222+2222+22222输出:33210#include stdio.h intmain{int a,n;int i,sn=0;scanfa,n;----------------------------------------------------1fori=l;i=n;i++------------------------2{sn+=a;---------------------------------3a=a*10+a;----------------------,4}printfsn=%d\n sn;return0;}则程序错误之处在.答案⑴以下程序是判断一个年份是否为闰年,若是闰年输出否则输出
13.XXXX isleap year;XXXXis notleap year.#include stdio.h intmain%{int yearleap=0;scanf cT,year;ifyear%4!=0------------------------------------------------1leap=0;else ifyear%100!=0-----------------------------------------------2leap=1;else ifyear%400!=0------------------------------3leap=0;else leap=1;if!leap----------------------4printfH%d isa leap year・\n”,year;else printf%d isnot aleapyear・\rT,year;return0;}则程序中错误之处是().答案:4#include stdio.h#include{double math.h ftdefineZERO IE-6int maina,b,c,disc,xl,x2;please inputdouble realpartimagpart;printfscanf%f%f%f,a,b,c;---a/b/c:\nH;---1iffabsa=IE-6-----------------------------------以下程序是求一元二次方程根的程序:
14.2printfMIt isnot aquadratic equation!\nM;else{disc=b*b-4*a*c;iffabsdisc=ZERO------------------------------------------------------3{xl=x2=-b/2*a;printfnIt hasequal roots:xl=x2=%
8.4f\nx1;}else ifdiscZERO-----------------------------------------------------------4{xl=■b+sqrtdisc/2*a;x2=-b-sqrtdisc/2*a;printfIt hasreal roots:xl=%
8.4f\tx2=%
8.4f\nH,xl,x2;}else{realpart=-b/2*a;imagpart=sqrt-disc/2*a;printfIt hascomplex roots:11;p rintfxl=%
8.4f+%
8.4fi\trealpartimagpart;printfH x2=%
8.4f-%
8.4fi\n11realpart^imagpart;}}return0;}求程序中错误的地方是()答案:1有以下自定义函数的程序:
15.#include stdio.h#includemath.hdouble max_twodouble x,double y{return xyx:y;}double max_threedoubledouble b,double c{double max=
0.0;max=max_twomax_twoa,b,c;return max;}intmain」{double x,y Zjres;scanfx.,y,,z;res=sqrt max_threex,y,z;printfThe maxnumber is%
0.2f\nres;re turn0;}则输入
4.
016.
025.00时,程序输出的结果是()・答案The maxnumberis
5.00以下程序是输出斐波那契数列的前个数:
16.40ftinclude stdio.h intmain{long f0=0fl=l f2;--------------------------------------------------J1int i;printfM%ld\t%ld\t,f0,f1;fori=l;i=40;i++-----------------------2{f2=f0+fl;--------------------------------------------3printfH%ld\t\f2;f0=fl;fl=f2;----------------------------------------------------------------------------------------4}return0;}在程序中错误之处是(),答案:2执行以下程序后,输出结果是().
17.#include stdio.h intmain{int s=0;fori=l;i=5;i++{ifi%2==0continue;s+=i;}printf,,%d\n,,s;return0;}J答案:当从键盘输入则下面程序的输出结果是()
18.abcXYZ,#include stdio.h intmain{char ch;whilech=getchar!=1\n1{ifch=1A,ch=1Z1ch+=32;else ifch=1a1ch=1z1ch=32;printf,%cn ch;}printfH\nH;return0;}J答案:ABCxyz。