c语言概述练习题(编辑修改稿)内容摘要:

) coutiendl。 } system(“ pause” )。 第 10 页 共 27 页 } ________________。 include iostream using namespace std。 void main() { int i=10,j=0。 do{ j=j+i。 i。 }while(i2)。 coutjendl。 system(“ pause” )。 } _____________________。 include iostream using namespace std。 void main() { int a=10,y=0。 do{ a+=2。 y+=a。 cout” a=” a” ,y=” yendl。 if(y20) break。 }while(a=14)。 system(“ pause” )。 } ,输出结果是 ________________。 include iostream using namespace std。 void main() { int x=23。 do{coutx。 }while(!x)。 system(“ pause” )。 } ___________________。 include iostream using namespace std。 void main() { int i,j,m=0,n=0。 for(i=0。 i2。 i++) for(j=0。 j2。 j++) if(j=i) m=1。 n++ coutnendl。 system(“ pause” )。 } ___________________。 include iostream 第 11 页 共 27 页 using namespace std。 void main() { int a,b。 for(a=1,b=1。 a=100。 a++) { if(b=10) break。 if(b%3==1) {b+=3。 continue。 } } coutaendl。 system(“ pause” )。 } ,输出结果是 __________________。 include iostream using namespace std。 void main() { int x=3,y=6,a=0。 while(x++!=(y=1)) { a+=1。 if(yx) break。 } cout” x=” x” ,y=” y” ,a=” aendl。 system(“ pause” )。 } 四、程序改错题 1.下面的程序用来求分段函数 )2(3)21(2)10(1)0(0xxxxy 的值,请将程序中的错误修改正确 include iostream using namespace std。 void main() { float x,y。 cinx。 if(x0) y=0。 if(x1) y=1。 if(x2) y=2。 else y=3。 第 12 页 共 27 页 cout” x=” x” ,y=” yendl。 system(“ pause” )。 } 1~ 100中所有能被 3整除的各数之和,结果放入变量 sum中。 请将程序修改正确,以得到正确的输出结果。 include iostream using namespace std。 void main() { int i,sum。 for(i=3。 i100。 i++) { sum=0。 sum+=i。 } cout” sum=” sumendl。 system(“ pause” )。 } :   )12(12 )2(75 653 431 22 2222   nn n 当 n的值很大时(例如, n=1000),下列程序运行是将会产生“溢出”错误,请修改程序,使之能正确计算。 include iostream using namespace std。 void main() { float pi=2。 for(int n=1。 n=1000。 n++) pi=pi*(2*n)*(2*n)/((2*n1)*(2*n+1))。 cout” pi=” piendl。 system(“ pause” )。 } 五、编程题 1.从键盘输入 100个整数,从中找出最大数和最小数。 2.编制程序计算两个整数 a和 b的最小公倍数。 3.试程序计算 1!+2!+„ +20!。 4.编制程序打印出 100以内的所有素数。 5.编制程序用辗转相除法求整数 a和 b的最大公约数。 习题四(函数) 一、选择题 C++函数的描述中,正确的是 __________。 ,但不可以嵌套调用 ,但可以嵌套调用 ,也不可以嵌套调用 ,也可以嵌套调用 C++函数的叙述中,正确的是 __________。 int型,变量 z为 float型,则该函数体内的语句 return(z)返回值的类型是 __________。 第 13 页 共 27 页 ,正确的是 __________。 ,其中一个参数设置成默认值后,其后所有参数都必须设置成默认值 个函数含有多个参数,则设置默认值参数时可以不连续设置默认值 ++语言中函数都必须设有默认值 ,如果实参是简单变量,它与对应形参之间的数据传递方式是 __________。 ,再由形参传给实参 __________。 include iostream using namespace std。 void fun(int x,int y,int z) {z=x*x+y*y。 } void main() { int a=31。 fun(5,2,a)。 coutaendl。 system(“ pause” )。 } void test(int a,int b=7,char c=’ *’ ),下面的函数调用中,属于不合法调用的是 __________。 (5) (5,8) (6,’ ’ ) (0,0,’ *’ ) __________。 include iostream using namespace std。 int d=1。 void fun(int p) { int d=5。 d+=p++。 coutd” ”。 } int main() { int a=3。 fun(a)。 d+=a++。 coutdendl。 } 4 6 4 5 : include iostream using namespace std。 int func(int a,int b) {return(a+b)。 } int main() { int x=2,y=5,z=8,r。 第 14 页 共 27 页 r=func(func(x,y),z)。 coutrendl。 } 该程序的输出结果是 __________。 C++语言中,形参的缺省存储类型是 __________。 __________。 include iostream using namespace std。 int f(int a) { int b=0。 statc int c=3。 a=c++,b++。 return a。 } int main() { int a=2,i,k。 for(i=0。 i2。 i++) k=f(a++)。 coutkendl。 } C++语言中,函数的隐含存储类型是 __________。 ,则该变量的存储类型是__________。 ,输出结果是 __________。 8 9 9 11 10 13 7 7 include iostream using namespace std。 int f(int a) { int b=0。 statc int c=3。 c++; b++。 return (a+b+c)。 } int main() { int a=2,i。 for(i=0。 i3。 i++) k=f(a)’ \t’。 coutendl。 } ,将出现的情况为 __________。 第 15 页 共 27 页 ,无法运行 : 3 : include iostream using namespace std。 int main() { void function(double val)。 double val。 function(val)。 coutvalendl。 return 0。 } void function(double val) {val=3。 } __________。 4 3 2 1 1 2 3 4 5 2 3 4 5 4 3 2 1 0 include iostream using namespace std。 void fun(int k) { if(k0) fun(k1)。 coutk” ”。 } int main() { int w=5。 fun(w)。 cout” \n”。 } ,错误的是 __________。 ,调用语句被替换成内联函数的函数体 __________。 test(),其原型是 int test(int,int,int),则下列重载函数声明中正确的是__________。 test(int,int,int) test(int,int,double) test(int,int,int =0) test(int,int,float ) 二、填空题 pi的功能是根据以下近似公式求 π 值: )/(1)33/(1)22/(116/)( nn   请将下面函数的空白处填写正确,以完成求π的功能。 include iostream using namespace std。 include cmath double pi(long n) { double s=。 第 16 页 共 27 页 long k。 for(k=1。 k=n。 k++) s=s+_____________。 return(sqrt(6*s))。 } __________。 include。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。