C++语言基础第1版习题答案

合集下载

C语言基础题及答案

C语言基础题及答案

C语言基础题及答案1、一个C语言的源程序中[正确答案:A]。

A)必须有一个主函数B)可以有多个主函数C)必须有主函数和其他函数D)可以没有主函数2、关于C程序的主函数,以下描述中正确的是[正确答案:B]。

A)C程序的第一个函数称为主函数,程序从该函数开始运行。

B)C程序的主函数即是main函数,程序从该函数开始运行。

C)C程序可以有多个主函数,程序从第一个主函数开始运行。

D)C程序可以没有主函数,程序从第一个函数开始运行。

3、C程序中,return语句的作用是[正确答案:D]。

A)终止程序运行B)返回到上层循环C)返回到外层结构D)返回到上层函数4、C语言程序的3种基本结构是[正确答案:A]。

A)顺序结构,选择结构,循环结构B)递归结构,循环结构,转移结构C)嵌套结构,递归结构,顺序结构D)循环结构,转移结构,顺序结构5、以下对C程序的描述中正确的是[正确答案:A]。

A)C程序总是从main()函数开始执行。

B)C程序可以从程序中的任何函数开始执行。

C)C程序总是从第一个定义的函数开始执行。

D)C程序中的main()函数必须放在程序的开始部分。

6、关于C程序第1行的包含语句,以下写法中正确的是[正确答案:D]。

A)#include stdio.h B)#include'stdio.h'C)#include(stdio.h)D)#include<stdio.h>7、关于C语言程序,正确的编程流程应该是[正确答案:A]。

A)编辑→保存→编译→运行B)编译→编辑→运行→保存C)保存→运行→编辑→编译D)运行→编译→保存→编辑8、下列的哪个不是C语言的关键字[正确答案:D]。

A)while B)auto C)break D)printf9、下列的哪个不是C语言的算术运算符[正确答案:C]。

A)+B)%C)=D)-10、下列的哪个不是C语言的关系运算符[正确答案:C]。

A)>=B)<=C)=D)!=11、下列的哪个是错误的描述[正确答案:D]。

C语言教材课后习题答案

C语言教材课后习题答案

2.简述程序设计语言发展的过程
程序设计语言经过最初的机器代码到今天接近自然语言的表达, 经过了四代的演变。 一 般认为机器语言是第一代,符号语言即汇编语言为第二代,面向过程的高级语言为第三代, 面对象的编程语言为第四代。
3.简述高级程序设计语言中面向过程与面向对象的概念。
“面向过程”是一种以过程为中心的编程思想。首先分析出解决问题所需要的步骤,然 后用函数把这些步骤一步一步地实现, 使用的时候依次调用函数即可。 一般的面向过程是从 上往下步步求精,所以面向过程最重要的是模块化的思想方法。 “面向对象”是一种以事物为中心的编程思想。面向对象的方法主要是将事物对象化, 对象包括属性与行为。 面向过程与面向对象的区别:在面向过程的程序设计中,程序员把精力放在计算机具体 执行操作的过程上,编程关注的是如何使用函数去实现既定的功能;而在面向对象的程序设 计中,技术人员将注意力集中在对象上,把对象看做程序运行时的基本成分。编程关注的是如 何把相关的功能(包括函数和数据)有组织地捆绑到一个对象身上。
不能使变量 k 得到正确数值的原因是: scanf("%d", &k);中的格式控制类型与变量 k 的定义类型不匹配,应将%d 改为%f.
习题 4 答案
选择题 1. B 2. A 3. B 4. B 阅读程序,写结果 7. 12 8.13 9. *0**2* 10. if(s>=90) m=4; else if(s>=80) m=3; else if(s>=70) m=2; else if(s>=60) m=1; else m=0; 11.输入 4 个整数 a,b,c,d,编写程序,将它们按从大到小顺序输出。 #include<stdio.h> main() { int a,b,c,d,t; scanf("%d%d%d%d",&a,&b,&c,&d); if(a<b) {t=a;a=b;b=t;} if(a<c) {t=a;a=c;c=t;} if(a<d) {t=a;a=d;d=t;} if(b<c) {t=b;b=c;c=t;} if(b<d) {t=b;b=d;d=t;} if(c<d) {t=c;c=d;d=t;} printf("%4d%4d%4d%4d",a,b,c,d); } 12.据所输入的 3 条边长值,判断它们能否构成三角形,如能构成,再判断是等腰三角形、 直角三角形还是一般三角形? 源程序: 5. C 6. B

c语言入门经典 习题答案

c语言入门经典 习题答案

c语言入门经典习题答案C语言入门经典习题答案C语言是一种广泛使用的编程语言,它被广泛应用于系统软件、应用软件、驱动程序、网络软件等领域。

对于初学者来说,掌握C语言的基础知识是非常重要的。

而经典的C语言习题则是帮助初学者巩固知识、提高编程能力的重要途径。

下面是一些C语言入门经典习题的答案,希望能够对初学者有所帮助:1. 编写一个程序,输入两个整数,输出它们的和。

```c#include <stdio.h>int main() {int a, b;printf("请输入两个整数:");scanf("%d %d", &a, &b);printf("它们的和是:%d\n", a + b);return 0;}```2. 编写一个程序,输入一个整数,判断它是奇数还是偶数。

```c#include <stdio.h>int main() {int num;printf("请输入一个整数:");scanf("%d", &num);if (num % 2 == 0) {printf("%d是偶数\n", num);} else {printf("%d是奇数\n", num);}return 0;}```3. 编写一个程序,输入一个字符,判断它是大写字母、小写字母还是数字。

```c#include <stdio.h>int main() {char ch;printf("请输入一个字符:");scanf(" %c", &ch);if (ch >= 'A' && ch <= 'Z') {printf("%c是大写字母\n", ch);} else if (ch >= 'a' && ch <= 'z') {printf("%c是小写字母\n", ch);} else if (ch >= '0' && ch <= '9') {printf("%c是数字\n", ch);} else {printf("%c是其他字符\n", ch);}return 0;}```以上是一些C语言入门经典习题的答案,希望对初学者有所帮助。

C语言基础知识课后习题答案

C语言基础知识课后习题答案

C语言基础知识课后习题答案说明:1、原先的少部分题目有错,请用红色的部分替换掉;2、如果红色部分有文字“删除该行”,就直接删除该行;第一章C语言的基础知识第一节对C语言的初步认识习题1. 下列叙述中错误的是BA)任何一个C程序都必须有且仅有一个main函数,C语言总是从main函数开始执行。

B)C语言中的变量,可以先使用后定义。

C)所有的C语言语句最后都必须有一个分号D)C程序书写格式自由,语句可以从任一列开始书写,一行内可以写多个语句。

第二节熟悉Visual C++习题1. C语言源程序名的后缀是 BA).exe B).c C).obj D).cp 2. 下列叙述中错误的是DA)计算机不能直接执行用C语言编写的源程序B)C程序经C编译后,生成后缀为.obj的文件是一个二进制文件C)后缀为.obj的文件,经连接程序生成后缀为.exe的文件是一个二进制文件D)后缀为.obj和.exe的二进制文件都可以直接运行3. 用C语言编写的代码程序BA)可立即执行B)是一个源程序C)经过编译即可执行D)经过编译解释才能执行第三节标识符习题1. 按照C语言规定的用户标识符命名规则,不能出现在标识符中的是BA)大写字母B)连接符C)数字字符D)下划线2. 以下选项中不合法的标识符是 CA)print B)FOR C)&a D)_003. 以下叙述中错误的是AA)用户所定义的标识符允许使用关键字B)用户所定义的标识符应尽量做到“见名知意”C)用户所定义的标识符必须以字母或下划线开头D)用户定义的标识符中,大、小写字母代表不同标识4. 可在C程序中用作用户标识符的一组标识符是AA)and B)Date C)HiD)case_2007 y-m-d Dr.T omBigl5. 以下不合法的用户标识符是CA)j2_KEY B)Double C)4d D)_8_6. 以下不能定义为用户标识符的是DA)Main B)_0 C)_int D)sizeof7. 下列选项中,不能用作标识符的是DA)_1234_ B)_1_2 C)int_2_ D)2_int_8. 以下4组用户定义标识符中,全部合法的一组是AA)_main B)If C)txt D)intenclude -max REAL k_2sin turbo 3COM _001第四节数制转换习题1.十进制整数360的八进制为__________,十六进制为_____________。

C语言程序设计基础教程习题答案

C语言程序设计基础教程习题答案

C语言程序设计基础教程习题答案习题答案第1章1.1 填空题1.1.1 应用程序ONEFUNC.C中只有一个函数,这个函数的名称是__main 。

1.1.2 一个函数由__函数头__和__函数体__两部分组成。

1.1.3 在C语言中,输入操作是由库函数__scanf 完成的,输出操作是由库函数_printf_完成的。

1.1.4 通过文字编辑建立的源程序文件的扩展名__是_.c;编译后生成目标程序文件,扩展名是__.obj__;连接后生成可执行程序文件,扩展名是_.exe_;运行得到结果。

1.1.5 C语言程序的基本单位或者模块是__函__数。

1.1.6 C语言程序的语句结束符是____;。

1.1.7 编写一个C程序,上机运行要经过的步骤:______________________________。

1.1.8 在一个C语言源程序中,注释部分两侧的分界符分别__为_/*和__*/__。

1.1.9 C语言中的标识符只能由三种字符组成,它们是字母、数字和下划线。

且第一个字符必须为字母或下划线。

1.1.10 C语言中的标识符可分为关键字、预定义标识符和用户标识符 3类。

1.2 选择题1.2.1 一个C程序的执行是从( A )。

A)本程序的main函数开始,到main函数结束B)本程序文件的第一个函数开始,到本程序文件的最后一个函数结束C)本程序的main函数开始,到本程序文件的最后一个函数结束D)本程序文件的第一个函数开始,到本程序main函数结束 1.2.2 以下叙述不正确的是(C)。

A)一个C源程序可由一个或多个函数组成B)一个C源程序必须包含一个main函数C) 在C程序中,注释说明只能位于一条语句的后面D) C程序的基本组成单位是函数1.2.3 C语言规定:在一个源程序中,main函数的位置( C )。

A)必须在程序的开头 B)必须在系统调用的库函数的后面C)可以在程序的任意位置 D)必须在程序的最后1.2.4 C编译程序是 (A)。

c语言第一章答案(Clanguage1)

c语言第一章答案(Clanguage1)

c语言第一章答案(C language 1)Chapter 1 basic knowledge of C languageFirst, the multiple-choice question1the answer is AA correct textbook, page 11, line secondB (} can be regarded as a sign of compound statementsThe C main function is not user namedThe D semicolon is the end of the statement. It must be part of the statementTo do this subject requires a thorough understanding of the concepts in the book2the answer is AThe A error textbook, page fourth, describes the user identifier like this 一when naming an identifierThe selection is customized by the user, but cannot be the same as the keyword, so the A option is incorrect, thisSubject to user identifierThe user identifier is an identifier, so it can be underlined, but the underlined character does not belong to the alphabet,Underline one of the numbers. This topic examines the concept of user identifiers.4the answer is BDefine is a predefined identifier, and a predefined identifier can be a user identifier, soDefine can be user ID, if is keyword, and keyword cannot be user identifier,Therefore, if cannot be a user identifier5the answer is DSizeof is the key word, refer to appendix twoNote: 6一13 examines the concept of user identifiers6the answer is DThe D answer begins with number 2 and does not conform to the identifier definition7the answer is C8the answer is DInt is the keyword9the answer is BThe answer A is the key word, the answer C starts with the number, does not conform to the concept, the answer D outThe decimal point is now displayed10the answer is AThe answer A has a decimal point11the answer is CAnswer C begins with numbers12the answer is AB answer, float is the key word,C answer, 3C to number 3 start,D answer in -5dNot one of the letters, numbers, or underscores13the answer is AB the answer is "-max - error”. InC answer, "3COM" begins with letter 3, and "D" in answerInt is a keyword, not a user identifier14the answer is BA answer 15. should not be a bit behind, C answer appears in the comma, D in the letter Bproblem15the answer is BThe last 8 lines of the eighth page of the textbook16the answer is B8 appears in B, and octal can only consist of 0 to 717the answer is DThe answer D begins with 0, not o18the answer is CIn answer A, E is followed by integers and 0. 5 by decimalsIn answer B, E cannot be empty laterIn answer D, E cannot be blank aheadThis topic examines the index representationThere is a problem with 2 in answer A, not decimal formIn answer B, E cannot be blank aheadIn answer D, E cannot be empty laterThis topic examines the index representation20the answer is AB in octal can not appear in the number 8,C in E can not be followed by decimal,D inE behindCan not be empty21the answer is B0.4 of B is decimal, incorrect22the answer is C0.5 of C is decimal, incorrect23the answer is D3. 6-5/2+1. 2+5%2=3. 6-2+1. 2+1=3. 8This topic examines arithmetic operators, noting that integers are divided by integers and that results can only be integers% cannot be used for real type calculations25the answer is DD answer, $does not belong to letters, numbers, underscores26the answer is AA the answer is a comma expression. In theB answer, x+l=y is the assignment expression, and the left is the changeVolume, and this is x=l, and similarly, the answer C is also wrong in x+10, in the D answer,The type conversion is mandatory,Correct is (double) x/1027the answer is AThe subject of this review is where the notes need to be noted, and the specific answers are shown in the middle of the second page of the textbook28the answer is BIn answer A, N2 is not defined. In answer C, you cannot use it before defining f. The answer is DThe middle of E must be an integer29the answer is CThe type of transformation is mandatory, and the k% (int) f is correct30the answer is DThis topic is similar to the textbook sixteenth page example 15, the solution is to seize ++m, 一n, 一m,The value of an expression is the value after the change of the variable, and the value of the n-- expression is the variation of the variable nPrevious value31the answer is BThis topic is the textbook tenth page example 9, the concrete solution sees the textbook, this topic inspects is negativeAn integer is the same as a unsigned positive integer stored in a computer, but not expressedThe same two numbersIn A answer, % operand cannot be real type, 26.8 error, assignment in B answerOperator, the left of the assignment operator must be a variable, so the assignment operator has the wrong 1+2 on the leftWrong, same answer, D error33the answer is CThis topic examines the first point about the addition and decrement operators on the fifteenth page of the textbookThat is only the operation object increment operator is variable, while in C + + (i+1).And i+1 is an expression34the answer is BThis topic examines the integer divided by integer. The result is an integer. In the B answer, the 1/2 result is 0, which leads to the value of the whole expression of 0, which is obviously wrong35the answer is D36the answer is ASee the last tenth lines of the thirteenth page of the textbookSimilarly, the type of aand B is doubleSee textbook ninth, page Two, fill in the blanks textbooks,Ninth pages,the last seventh linestextbooks,third pages,the last fifth lines textbooks,Ninth pages,the last sixth linestextbooks,This topic examines the value of the n++ expression as the value before the change of N, and then increases the value of N by37the answer is BC=a/b+0. 4, c=8/5+0. 4, c=l+0. 4, c=l. 4, because C is int, so the value of n is 1. To do this, you need to read the title carefully 38the answer is D(int) a+b/b= (int) 5. 5+2. 5/2. 5=5+1. 000000-b=6. 00000039the answer is Dseventh pages, the last fifth lines5 textbooks, eighth pages, integer variables, and eleventh page variables6 5+3. 6/2=5+l. 8=6. 8The value of the 7 a++ expression is the value before the change of a, and, of course, a itself is increased by 18 assign 10 to variable B。

C语言基础练习1题含答案

C语言基础练习1题含答案

C语⾔基础练习1题含答案C语⾔基础练习100题(含答案)雷柳青编排1、下⾯程序的输出是________#include<>voidmain(){intk=11;printf("k=%d,k=%o,k=%x\n",k,k,k);}A)k=11,k=12,k=11B)k=11,k=13,k=13C)k=11,k=013,k=0xbD)k=11,k=13,k=b2、在下列选项中,不正确的赋值语句是________.A)++t;B)n1=(n2=(n3=0));C)k=i=j;D)a=b+c=1;3、下⾯合法的C语⾔字符常量是__________.A)'\t'B)"A"C)65D)A4、字符(char)型数据在微机内存中的存储形式是____.A)反码B)补码C)EBCDIC码D)ASCII码5、设inta=12,则执⾏完语句a+=a-=a*a后,a的值是________A)552B)264 C)144D)-2646、执⾏下⾯程序中的输出语句后,输出结果是______.#include<>voidmain(){inta;printf("%d\n",(a=3*5,a*4,a+5));}A)65B)20 C)15D)107、下⾯程序的输出是__________.#include<>voidmain(){intx=023;printf("%d\n",--x);8、下⾯程序的输出是___________.#include<>voidmain(){charch1,ch2;ch1='A'+'5'-'3';ch2='A'+'6'-'3';printf("%d,%c\n",ch1,ch2);}A)67,DB)B,CC)C,DD)不确定的值9、以下程序的输出结果是________.#include<>voidmain(){intx=10,y=10;printf("%d%d\n",x--,--y);}A)1010B)99 C)910D)10910、若x和y都是int型变量,x=100,y=200,且有下⾯的程序⽚段: printf("%d",(x,y));上⾯程序⽚段的输出结果是_______.A)200B)100C)100200D)输出格式符不够,输出不确定的值11、阅读下⾯的程序#include<>voidmain(){inti,j;i=010;j=9;printf("%d,%d",i-j,i+j);}则程序的运⾏结果是________.A)1,19B)-1,19 C)1,17D)-1,1712、阅读下⾯的程序m=++i;n=j++;printf("%d,%d,%d,%d",i,j,m,n);}程序的运⾏结果是_________.A)8,10,8,10B)9,11,8,10C)9,11,9,10D)9,10,9,1113、若已定义inta,则表达式a=10,a+10,a++的值是___.A)20B)10 C)21D)1114、阅读下⾯的程序#include<>voidmain(){inti,j;scanf("%3d%2d",&i,&j);printf("i=%d,j=%d\n",i,j);}如果从键盘上输⼊1234567<回车>,则程序的运⾏结果是________.A)i=123,j=4567B)i=1234,j=567C)i=1,j=2D)i=123,j=4515、下⾯程序的输出结果是________.#include<>voidmain(){inta=-1,b=4,k;k=(++a<=0)&&(b--<=0);printf("%d,%d,%d\n",k,a,b);}A)1,1,2B)1,0,3 C)0,1,2D)0,0,316、下⾯程序的输出结果是_______.printf("%d,%d\n",a+b!=a-b,x<=(y-=);}A)1,0B)0,1 C)1,1D)0,017、若有以下定义和语句:inta=010,b=0x10,c=10;printf("%d,%d,%d\n",a,b,c);则输出结果是_________.A)10,10,10B)8,16,10 C)8,10,10D)8,8,1018、已知有double型变量x=,y=,整型变量a=7, 则表达式x+a%3*(int)(x+y)%2/4的值是_________.A)2.5 C)019、设有以下语句:intx=10;x+=3+x%3,则x的值是._________A)14B)15 C)11D)12 20、若d为double型变量,则表达式d=1,d+5,d++的值是_______.A)1B)6.0 C)21、若有定义inta=12,n=5,则表达式a%=(n%2)运算后,a的值__________.A)0B)1 C)12D)622、若有定义intx=3,y=2和floata=,b=,则表达式:(x+y)%2+(int)a/(int)b的值是____.A)0B)2 C)123、在C语⾔中,以下叙述不正确的是________.A)在C程序中,⽆论是整数还是实数,都能被准确⽆误的表⽰B)在C程序中,变量名代表存储器中的⼀个位置C)静态变量的⽣存期与整个程序的⽣存期相同D)C语⾔中变量必须先定义后引⽤24、设a为整型变量,不能正确表达数学关系10A)10C)a>10&&a<15D)!(a<=10)&&!(a>=15)25、如果c为字符型变量,判断c是否为空格不能使⽤________.(假设已知空格ASCII码为32)A)if(c=='32')B)if(c==32)#include<>voidmain(){intk;charcp;cp=getchar();if(cp>='0'&&cp<='9')k=cp-'0';elseif(cp>='a'&&cp<='f')k=cp-'a'+10;elsek=cp-'A'+10;printf("%d\n",k);}A)2B)4 C)1D)1027、执⾏下⾯程序后,运⾏结果是________.#include<>voidmain(){intx=41,y=1;if(x%3==0&&x%7==0){y+=x;printf("y=%d\n",y);}else{y=x;printf("y=%d",y);}}A)y=41B)y=43 C)y=42D)y=128、运⾏下⾯程序时,从键盘输⼊"12,34,9",则输出结果是______. #include<>voidmain(){intx,y,z;scanf("%d,%d,%d",&x,&y,&z);if(xif(yelseprintf("%d\n",y);elseif(xelseprintf("%d\n",x);}输出结果是________.#include<>voidmain(){charch;ch=getchar();switch(ch){case'H':printf("Hello!\n");case'G':printf("Goodmorning!\n");default:printf("Bye_Bye!\n");}}A)Hello!B)Hello!GoodMorning!C)Hello!D)Hello!Good morning!Bye_Bye!Bye_Bye!30、执⾏下列程序段后的输出结果是_________.intx=1,y=1,z=1;x+=y+=z;printf("%d\n",xA)3B)2 C)1D)431、设ch是char型变量,值为'A',则表达式ch=(ch>='A'&&ch<='Z')?ch+32:ch的值是_____.A)ZB)aC)zD)A32、下⾯程序的输出结果是________.#include<>voidmain(){intx=8,y=-7,z=9;if(xif(y<0)z=0;elsez-=1;printf("%d\n",z);#include<>voidmain(){inta,b,s;scanf("%d,%d",&a,&b);s=a;if(ss=s*s;printf("%d\n",s);}A)14B)16 C)18D)2034、下列程序的执⾏结果是_________.#include<>voidmain(){intx=0,y=1,z=0;if(x=z=y)x=3;printf("%d,%d\n",x,z);}A)3,0B)0,0 C)0,1D)3,135、能够完成如下函数计算的程序段是______. ┌-1x<0 y=┤0x=0└1x>0A)y=1;B)if(x>=0)if(x!=0)if(x>0)y=1;if(x>0)y=1;elsey=0;elsey=0;elsey=-1;C)y=0;D)y=-1;if(x>=0)if(x>0)y=1;if(x>0)y=1;elsey=0;elsey=-1;36、以下程序的执⾏结果是________.#include<>voidmain()case1:switch(y){case0:printf("first\n");break;case1:printf("second\n");break;}case2:printf("third\n");}}A)firstB)firstsecondthirdC)firstD)secondthird37、以下程序的执⾏结果是________.#include<>voidmain(){inta,b,c,d,x;a=c=0;b=1;d=20;if(a)d=d-10;elseif(!b)if(!c)x=15;elsex=25;printf("d=%d\n",d);}A)d=20B)d=10 C)d=15D)2538、下列程序执⾏后的输出结果是________. #include<> voidmain(){intx,y=1,z;if((z=y)<0)x=4;elseif(y==0)x=5;A)4,1B)6,1 C)5,0D)出错信息39、有如下程序#include<>voidmain(){intx=1,a=0,b=0;switch(x){case0:b++;case1:a++;case2:a++;b++;}printf("a=%d,b=%d\n",a,b);}该程序的输出结果是__________.A)a=2,b=1B)a=1,b=1 C)a=1,b=0D)a=2,b=240、下⾯程序的输出结果是_________.#include<>voidmain(){inta=-1,b=1,k;if((++a<0)&&(b--<=0)) printf("%d%d\n",a,b);elseprintf("%d%d\n",b,a);}A)-11B)01 C)10D)0041、假定w、x、y、z、m均为int型变量,有如下程序段:w=1;x=2;y=3;z=4;m=(w则该程序段执⾏后,m的值是_________.A)4B)3 C)2D)142、以下程序的输出结果是_________.main(){inta=100;A)a<=100B)100 C)0D)143、若执⾏下⾯的程序从键盘上输⼊9,则输出结果是.______________ #include<>voidmain(){intn;scanf("%d",&n);if(n++<10)printf("%d\n",n);elseprintf("%d\n",n--);}A)11B)10 C)9D)844、以下程序段运⾏结果是________.intx=1,y=1,z=-1;x+=y+=z;printf("%d\n",xA)1B)2 C)4D)不确定的值45、有以下程序#include<>voidmain(){inta,b,c=246;a=c/100%9;b=(-1)&&(-1);printf("%d,%d\n",a,b);}输出结果是________.A)2,1B)3,2 C)4,3D)2,-146、运⾏下⾯程序时,若从键盘输⼊数据为"123",则输出结果是_______.#include""voidmain(){intnum,i,j,k,place;scanf("%d",&num);if(num>99)place=3;elseplace=1;i=num/100;j=(num-i*100)/10;k=(num-i*100-j*10);switch(place){case3:printf("%d%d%d\n",k,j,i);break;case2:printf("%d%d\n",k,j);break;case1:printf("%d\n",k);}}A)123B)1,2,3 C)321D)3,2,147、执⾏下列程序后的输出结果是_______. #include<> voidmain(){intk=4,a=3,b=2,c=1;printf("%d\n",k}A)4B)3 C)2D)148、以下条件表达式中能完全等价于条件表达式if(x)中的x的是____.A)(x==0)B)(x!=0)C)(x==1)D)(x!=1)49、若运⾏下⾯程序时,给变量a输⼊15,则输出结果是______.#include<>voidmain(){inta,b;scanf("%d",&a);b=a>15?a+10:a-10;printf("%d\n",b);}A)5B)25 C)15D)1050、执⾏下⾯程序的输出结果是________.#include<>voidmain(){inta=5,b=0,c=0;if(a=a+b)printf("****\n");elseprintf("####\n");}A)有语法错误不能编译B)能通过编译,但不能通过连接C)输出****D)输出####51、为了避免嵌套的if-else语句的⼆义性,C 语⾔规定else总是与______组成配对关系.A)缩排位置相同的ifB)在其之前未配对的ifC)在其之前尚未配对的最近的ifD)同⼀⾏上的if52、以下程序段__________.x=-1;do{x=x*x;}while(!x);A)是死循环B)循环执⾏两次C)循环执⾏⼀次D)有语法错误53、对下⾯程序段描述正确的是_______.intx=0,s=0;while(!x!=0)s+=++x;printf("%d",s);A)运⾏程序段后输出0B)运⾏程序段后输出1C)程序段中的控制表达式是⾮法的D)程序段循环⽆数次54、下⾯程序段的输出结果是_______.x=3;do{y=x--;if(!y){printf("*");continue;}printf("#");}while(x=2);A)##B)##*C)死循环D)输出错误信息55、下⾯程序的运⾏结果是_______.#include<>voidmain(){inta=1,b=10;do{b-=a;a++;}while(b--<0);printf("%d,%d\n",a,b);}A)3,11B)2,8 C)1,-1D)4,956、下⾯程序段的运⾏结果是__________. intn=0; while(n++<=2)printf("%d",n);A)012B)123 C)234D)错误信息57、下⾯程序段的运⾏结果是________.intx=0,y=0;while(x<15)y++,x+=++y;printf("%d,%d",y,x);A)20,7B)6,12 C)20,8D)8,2058、下⾯程序的运⾏结果是________.#include<>voidmain(){ints=0,i=1;while(s<=10){s=s+i*i;i++;}printf("%d",--i);}A)4B)3 C)5D)659、下⾯程序段的运⾏结果是________.for(x=10;x>3;x--){if(x%3)x--;--x;--x;printf("%d",x);}A)63B)74 C)62D)7360、下⾯程序的运⾏结果是________.#include<>voidmain(){inta,b;a=-1;b=0;do{++a;++a;b+=a;}while(a<9);printf("%d\n",b);}A)34B)24 C)26D)2561、下⾯程序段的运⾏结果是___________. for(i=1;i<=5;)printf("%d",i);i++;A)12345B)1234 C)15D)⽆限循环62、下⾯程序的输出结果是__________.#include<>voidmain(){intn=4;while(n--)printf("%d",n--);}A)20B)31 C)321D)21063、以下程序运⾏后的输出结果是________. #include<>voidmain(){inti=10,j=0;do{j=j+1;i--;}while(i>2);printf("%d\n",j);}A)50B)52 C)51D)864、有如下程序#include<>voidmain(){intx=23;do{printf("%d",x--);}while(!x);}该程序的执⾏结果是_______A)321B)23C)不输出任何内容D)陷⼊死循环65、以下程序段的执⾏结果是_______. inti,j,m=0;for(i=1;i<=15;i+=4)for(j=3;j<=19;j+=4)m++;printf("%d\n",m);A)12B)15 C)20D)2566、下⾯程序的输出结果是___________. #include<>voidmain(){inti;for(i=1;i<6;i++){if(i%2!=0){printf("#");continue;}printf("*");}printf("\n");}A)#*#*#B)#####C)*****D)*#*#*67、下⾯程序的输出结果是__________. #include<>voidmain(){intx=10,y=10,i;for(i=0;x>8;y=++i)printf("%d%d",x--,y);}A)10192B)9876C)10990D)10109168、执⾏以下程序后,输出的结果是__________.#include<>voidmain(){inty=10;do{y--;}while(--y);printf("%d\n",y--);}A)-1B)1C)8D)069、有如下程序#include<>voidmain(){intn=9;while(n>6){n--;printf("%d",n);}}该程序段的输出结果是__________.A)987B)876 C)8765D)987670、有如下程序#include<>voidmain(){inti,sum=0;for(i=1;i<=3;sum++)sum+=i;printf("%d\n",sum);}该程序的执⾏结果是___________.A)6B)3 C)死循环D)071、以下循环体的执⾏次数是_______ #include<>voidmain(){inti,j;for(i=0,j=1;i<=j+1;i+=2,j--)printf("%d\n",i);}A)3B)2 C)1D)072、在执⾏以下程序时,如果从键盘上输⼊:ABCdef<回车>,则输出为________. #include<>voidmain(){charch;while((ch=getchar())!='\n'){if(ch>='A'&&ch<='Z')ch=ch+32;elseif(ch>='a'&&ch<'z')ch=ch-32;printf("%c",ch);}printf("\n");}A)ABCdefB)abcDEFC)abcD)DEF 73、下⾯程序的输出结果是__________.main(){inti,k=0,a=0,b=0;for(i=1;i<=4;i++){k++;if(k%2==0){a=a+k;continue;}b=b+k;a=a+k;}printf("k=%da=%db=%d\n",k,a,b);}A)k=5 a=10b=4B)k=3 a=6b=4C)k=4 a=10b=3D)k=4 a=10b=474、执⾏下⾯程序段后,k的值是_________. inti,j,k;for(i=0,j=10;ik=i+j;A)9B)11 C)8D)1075、以下程序的功能是:从键盘上输⼊若⼲个学⽣的成绩,统计并输出最⾼成绩和最低成绩,当输⼊负数时结束输⼊。

C语言程序设计基础第一章习题答案

C语言程序设计基础第一章习题答案
4、D(“{}“必须成对出现)
5、C(参考P9,2.编译)
二、填空题
1、函数
2、.c;.obg;.exe
3、机器语言;汇编语言;高级语言;机器语言;高级语言
4、顺序结构;选择结构;循环结构
5、当型循环;直到型循环
三、问答题
1、答:所谓程序就是一组计算机能够识别和执行的指令;程序设计是指利用计算机解决问题的全过程。
2、答:源程序:用高级语言编写的程序;
目标程序:把源程序翻译成的二进制程序;
可执行程序:把目标程序和与系统的函数库以及其他目标程序连接起来形成的程序。
3、答:参考P4
四、编程题
1、答:
#include”stdio.h”
int main()
{
printf(“Happy new year!\n”);
}
2、答:
#include”stdio.h”;
scanf("%d%d",&a,&b);
if(a<b)printf("min=%d\n",a);
else printf("min=%d\n",b);
}
第一章(P14)
一、选择题
1、B(P14小结中的第三段)
2、D(参考P9,3.链接部分的内容)
3、A(B选项,“{}”除了做可以作为函数体的定界符意外还可以作为一个程序块的分节符等;C选项,不是所有的奇函数可以由用户命名的如”main“函数;D选项,分号是C语句的必要组成部分,是不可缺少的。)
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

C++语言基础实用教程习题参考解答第一章 C++语言概述1.2 填空题1.#2. ; { }3. 空格制表回车换行4. 系统用户5. 程序6. 函数头函数体7. main8. 函数原型9. 原型10. 复合语句11. .h .cpp12. 严重错误警告错误13. void14. void15. int 016. n17. 下一行18. 空白符1.3 写出下列程序运行结果,此题又作为上机实验题1. x+y=11,x*y=302. cube(3)=27cube(5)=125cube(8)=5123. averageValue:3averageValue:44. 请输入三个整数:10 5 9 (假定输入的三个整数为10,5,9)最大值: 10最小值: 5第二章数据类型和表达式2.2 填空题1. 4,1,1,4,82. short, int, long3. 4, 2, 24. 46, 123, 985. 107, 10, 92, 42 1026. 157. 符号常量,整数,int8. 3.4E2, 5.27E69. int, int, double, double, float10. x, 1511. 6, 6012. 26, 2513. 4, 114. 256, 2215. x, x16. 0, 117. 2018. 519. 9, 21620. 0, 1921. (1+x)*sin(48*3.14159/180), a*pow(x,b)*exp(x+1) 2.3 指出下列各表达式值的类型1. int2. double3. float4. long int5. int6. int7. int8. int9. double10. double11. double12. int13. int 14. double 15. char 16. int17. bool 18. int 19. short 20. bool21. unsigned int 22. double 23. int 24. char25. int 26. double 27. double 28. double29. double 30. int 31. int 32. double33. double 34. double 35. bool 36. bool37. bool 38. bool 39. bool 40. bool2.4 已知a=20, x=4.7, r='a', 试求出下列每个表达式的值(各表达式互不影响)。

1. 202. 'b'3. 04. 45. 76. 37. 2.58. 'e'9. 18.410. '2'11. 4012. 16513. 114. 015. 016. 117. 118. 019. 3020. 1021. 9722. 5023. 24324. 30.525. -626. 527. 528. 42.5 给出下列每个逻辑表达式的相反式1. !x2. x!=03. a==true4. x<105. x==key || !flag6. p==NULL || flag==false7. x<=0 || x>=108. x!=key && false9. x<a && true10. ch!='d' && ch!='D'11. p || p->data==x12. i>=n || a[i]==key13. ch!='(' && ch!= '[' && ch!='{'14. !x && (i>=n || i==0)2.6 把下列数学算式或不等式表示成C++表达式1. 2*x*(1+x*x/3.0)2. (1+exp(x))/(1-exp(x))4. 1/(pow(3,x)*log(2*x+k))5. pow(sin(x+PI/4),3)/(3+pow(cos(x-PI/4),3)) //其中PI常量为3.141596. 1/7.0*pow((1+exp(x+1)),n)7. x>=0 && x<=208. a*x-b*y!=c9. 4*x+7*y-2==3*a*b10. fabs((2*x*x+1)/(3*x+2))<=5 && (3*x+2!=0)11. age>=55 || pay>=82012. place== "江苏" && sex== "女"3.(-b+sqrt(b*b-4*a*c))/(2*a)13. (ch>='a' && ch<='z') || (ch>='A' && ch<='Z')14. s[0]=='0' && (s[1]=='x' || s[1]==’X’)2.7 写出下列每个程序运行后的输出结果并自行上机验证1. 0,1,2,32. p=62.8318s=314.1593. 1 1 12 2 23 1 84. 1 1 2 4 4 4 8 8 4 45. 30 120 730 10 3030 20 106. 1 1 0 0 0 17. 5 10 1515 10 15150 10 150151 11 10152 12 1518. 15.72 16 1515.72 16 15.715.72 16 15.7第三章流程控制语句3.1 填空题1. 选择,循环,跳转2. goto, continue, break, return3. 结构性4. 常量表达式5. if6. switch7. 不停止8. switch9. 1, n+1, n10. 循环条件,循环体11. 循环, switch,循环12. 循环体,循环体13. do, 右花括号14. do, for, while15. 1016. 1117. 1018. break19. continue20. return3.2 写出下列每个程序运行后的输出结果并上机验证1. 121a,b,c=7,12,302. 11 14 switch end.3. 36 -5 73 192 8 4436 139-5 173 8192 138 6744 1714. 36 25 20 43 12 70 66 34 28 15 32 55129 255 525. 1 1 12 2 33 6 94 24 336. 10 6 47. ***************8. 1 5 7 11 13 17 19 23 25 29 1509. +**+k=1110. 1 42 62 33 55 6c=3711. s=6312. 请输入两个正整数x和y:24 88x和y的最小公倍数:2643.3 指出下列每个程序的功能并上机验证1. 计算并输出的值,其中a的值由键盘输入。

2. 根据,计算并打印出每一个x值所对应的y值,其中a和每次的x值均由键盘输入,直到从键盘上输入终止标志-1为止。

3. 根据从键盘上输入的两个实数和一个四则算术运算符求出运算结果。

4. 把从键盘上输入的一个整数分解为所有可能的每两个因子之积。

5. 计算并输出的值,其中N值由键盘输入。

6. 根据从键盘上输入的x和n的值计算并输出y的值,y的计算公式为:7. 在输出屏幕上打印出一个由字符'*'组成的等腰三角形,该三角形的高为5行,底边宽为9个字符。

8. 求出从键盘上输入的两个整数的最大公约数和最小公倍数。

9. 让计算机随机出10道20以内整数的加法题供用户计算,每道题10分,计算完成后打印出得分。

10. 求解一元二次方程ax2+bx+c=0的根。

第四章数组和字符串4.1 填空题1. i+12. 40 a+203. 192 a+1364. 300 a+945. 9 76. 3 8 07. 1 28. 0 19. 810. 1111. n+1 n+112. 字符串字符串13. 10 1914. '1' '4'15. "456" "" (或空串)16. 5 117. "abcdef"18. strcpy(a,"aaa")19. 320. 221. Integer int int22. AA 10 int23. BB 10 50 500 char24. 4 6 24 int4.2 写出下列程序运行后的输出结果1. 6 42. 66 553. 14 254. 4 3 145. 4 3 2 2 36. 2 1 5 27. 1 3 128. worker cadre9. 4 1 8 -14.3 指出下列每个函数的功能1. 使数组a中的n个元素的值按相反的次序排列。

2. 显示输出数组a中大于等于n个元素平均值的所有元素值。

3. 分别统计并输出字符数组a所指字符串中各自出现的',',';','('和')','['和']','{'和'}'等字符的个数。

4. 对于二维字符数组a中保存的M个字符串,分别统计并输出其长度小于5、大于等于5且小于15、大于等于15的字符串个数。

第五章指针5.1 填空题1. 42. 地址 DataType*3. (char*)p4. int**5. *p &p6. *p p7. *p *p8. 259. 4210. 2611. 4212. 4*i13. *(a+i)14. a+i*sizeof(a[i])15. 第一个修改16. b[7] b[2]17. int *p=&x;18. *p19. int[n] int *20. c[3][0] c[3][2]21. int(*)[6]22. char[20] char* f[i][0]23. *(a[i]+j) 或*(*(a+i)+j)或*(a+i)[j]24. int &y=x;25. x26. 相等 x27. *p28. 0 p[0] *P29. 'a'30. char(*)[n]31. delete p32. delete []p5.2 写出下列每个程序运行后的输出结果并上机验证1. 1 2 32. 3 5 7 911 13 15 173. 229 45 45.84. 72 245. 3 6 9 12 1515 12 9 6 36. 4 12 20 287. 20 4030 608. 17 1752 529. computertypewritertelephone10. aremac camera11. 7 4 5 10 312. 24 2449 4913. 5 1515 514. 0 1 1 2 3 58 13 21 34 55 89第六章函数6.1 填空题1. 引用2. char* a3. int (*w)[N]4. 不能够5. 不能够能够6. 实参7. 函数声明8. 实参的值地址9. 实参10. return return11. 数组指针12. 全局文件函数局部13. 能够14. 无关15. 有关不同16. 不同相同17. 不能够相同18. 可以19. 内层外层20. 原型语句21. 自己22. 递归递归23. 相同不同24. 不是不可以25. 函数调用表达式26. 普通函数27. 模板函数28. int& (*ff)(int[], int) 6.2 给出下列程序运行后的输出结果1. 10 2030 6530 202. 10 2015 35 510 203. x=13, y=21x=5, y=8, z=344. x,y=10, 26x,y=26, 10x,y=10, 26x,y=25, 115. 666. 253787. motion telephone8. 12 49. 6 5 4 3 2 1 09110.v1=4v2=5.5511.操作成功!操作成功!操作成功!25 48 50 8266 43 75s t u de n t wFile Edit Insert ProjectBuild12.输入矩阵的行数和列数:3 41 2 3 42 4 6 83 6 9 126.3 指出下列每个函数的功能1. 求出的值。

相关文档
最新文档