C++复习程序题_第1页
C++复习程序题_第2页
C++复习程序题_第3页
C++复习程序题_第4页
C++复习程序题_第5页
已阅读5页,还剩22页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 1输入3个数a,b,c,输出其中的最大数。 2、x J x1 y= 2x-11=x=10 3、 ( 1)给出一个百分制成绩,要求输出等级。成绩分为5个等级,分别为A(90-100 ), B( 80-89),C( 70-79),D (60-69),E( 0-59) (2) 输入一个正整数 n,再输入n个学生的成绩,计算平均分,并统计各等级成 绩的个数。成绩分为5个等级,分别为A( 90-100),B( 80-89),( 70-79),D( 60-69), E ( 0-59) (3) 输入一些学生的成绩,统计其中最高分和平均值,输入遇负数结束。(例题) 4、 求出10至1000之内能同时被2、3

2、、7整除的数,并输出。 5、(1)1+2+ +100 1+3+5+99 2+4+6+100 、1 、2 .n , n 从键盘输入 (5) ,1 . 1 .2 .1 2, 3 .1 n 6、分数序列之和 。 (1) 求出分数序列 2/1,3/2, 5/3,8/5,13/8 - ,的前二十项之和。 (2) 求出分数序列 2/4,4/7, 6/10 , 8/13, 10/16 , 12/19,的前二十项之和。 7、(1)求 n! (2)1!+2!+n! , n从键盘输入 8、求s=a+aa+aa,共n个,其中n和a从键盘输入。 9、(1)输入一个字符,如果是大写字母,将其转换为小写(小写字母转换为大

3、 写同理,自己写) (2)、输入一行字符,分别统计其中英文字母,数字,空格,其他字符的个数。 10、(1)求水仙花数 (2) 给出一个不多于 5 位的正整数,求出它是几位数及各位上的数字 11、打印出下列图形(用循环完成) * * 1 1 2 1 2 3 1 2 3 4 12、将一个一维数组逆序输出 13、求 Fibonacci 数列。 14、冒泡排序法。 解法: 1、输入 3 个数 a,b,c, 输出其中的最大数。 #in elude using n amespace std; int mai n () int a,b,c,max; cin abc; if (ab) max=a; else

4、max=b; if (cmax) max=c; else max=max; coutmax; return 0; 2、x J x1 y= 2x-11=x=10 #in clude using n amespace std; int main ( ) int x,y; cinx; if (x1) y=x; else if (x10) y=2*x-1; else y=3*x-11; coutx=x, y=y; return 0; 3、( 1) 给出一个百分制成绩,要求输出等级。成绩分为5 个等级,分别为 A (90-100),B(80-89 ),C( 70-79 ), D( 60-69 ), E(

5、 0-59 ) #include using namespace std; int main ( ) int score; char grade; cinscore; if(score=90) grade= A J else if(score=80) grade= B else if (score=70) grade= C else if (score=60) grade= D else grade=E ; coutgrade; return 0; (2)输入一个正整数n,再输入n个学生的成绩,计算平均分,并统计各等级 成绩的个数。成绩分为 5 个等级,分别为 A ( 90-100 ) ,B

6、( 80-89 ) ,C ( 70-79 ), D( 60-69 ), E( 0-59 ) #include using namespace std; int main ( ) int n,i,score,sum=0,ave,a=0,b=0,c=0,d=0,e=0; cinn; for(i=1;iscore; if(score=90) a+; else if(score=80) b+; else if (score=70) c+; else if (score=60) d+; else e+; sum=sum+score; ave=sum/n; coutaveabcde; return 0;

7、(3) 输入一些学生的成绩,统计其中最高分和平均值,输入遇负数结束。 #include using namespace std; int main ( ) int score,max=0,sum=0,ave,i=0; cinscore; while(score=0) i+; sum=sum+score; if(scoremax) max=score; cinscore; ave=sum/i; coutave ”, ” max; return 0; 4、求出 10 至 1000 之内能同时被 2、3、7 整除的数,并输出。 #include using namespace std; int ma

8、in ( ) int n; for(n=10;n=1000;n+) if(n%2=0 return 0; 5、(1)1+2+100书上例题,自己写 #include using namespace std; int main ( ) int i,sum=0; for(i=1;i=100;i+) sum=sum+i; coutsum; return 0; (2) 1+3+5+99 同上,自己写 #include using namespace std; int main ( ) int i,sum=0; for(i=1;i=100;i=i+2) sum=sum+i; coutsum; retur

9、n 0; (3) 2+4+6+100 同上,自己写 #include using namespace std; int mai n () int i,sum=O; for(i=2;i=100;i=i+2) sum=sum+i; coutsum; return 0; ,12n , n从键盘输入 #in clude #in clude using n amespace std; int mai n () float i,sum=0,n; cinn; for(i=1;i=n ;i+) sum=sum+sqrt(i); coutsum; return 0; (5). 11, 2. 1.2,3. 1.

10、n #in clude #in clude using n amespace std; int mai n () float i,sum1=0,sum=0,n; cinn; for(i=1;i=n ;i+) sum1=sum1+sqrt(i); sum=sum+sum1; coutsum; return 0; 6、分数序列之和 (1)求出分数序列 2/1 , 3/2 , 5/3 , 8/5 , 13/8,的前二十项之和。 #include using namespace std; int main() int i,t,n=20; double a=2,b=1,s=0; for (i=1;i=n

11、;i+) s=s+a/b; t=a; a=a+b; b=t; coutsum=sendl; return 0; (2)求出分数序列 2/4 , 4/7, 6/10 , 8/13, 10/16 , 12/19,的前二十项之和。 #include using namespace std; int main() int i; double a,b,s=0; for (i=1;i=20;i+) a =2*i ; b=3*i+1; s=s+a/b; coutsum=sendl; return 0; 7、(1) 求 n! #include using namespace std; int main ( )

12、 int n , i; float t=1; cinn; for (i=1;i=n;i+) t=t*i; cout t endl; return 0; (2)1!+2!+n! #include using namespace std; int main () float s=0,t=1; int n; for (n=1;n=20;n+) t=t*n; s=s+t; cout1!+2!+.+20!=sendl; return 0; 8、求s=a+aa+aa,共n个,其中n和a从键盘输入。 #include using namespace std; int main ( ) int n,a,i,s

13、um=0,t=0; cinna; for (i=1;i=n;i+) t=t+a; sum=sum+t; a=a*10; coutsum endl; return 0; 9、(1) 输入一个字符,如果是大写字母,将其转换为小写(小写字母转换为大写 同理,自己写) #include using namespace std; int main ( ) char ch; ch=getchar( ); if( ch=A putchar(ch); return 0; (2) 、输入一行字符 , 分别统计其中英文字母,数字,空格,其他字符的个数。 #include using namespace std;

14、int main ( ) char c; int letters=0,space=0,digit=0,other=0; while(c=getchar()!=n) if (c=a else other+; coutletter:letters,space:space,digit:digit,other :other; return 0; 10、 (1) 求水仙花数 #include using namespace std; int main () int i,j,k,n; for (n=100;n1000;n+) i=n/100; j=n/10-i*10; k=n%10; if (n = i*

15、i*i + j*j*j + k*k*k) coutn coutendl; return 0; (2) 给出一个不多于 5 位的正整数,求出它是几位数及各位上的数字 #include using namespace std; int main ( ) long int n; int wei,wan,qian,bai,shi,ge; cinn; if(n99999) cout9999) wei=5; else if(n999) wei=4; else if(n99) wei=3; else if(n9) wei=2; else wei=1; wan=n/10000; qian=n%10000/10

16、00; bai=n%1000/100; * shi=n%100/10; ge=n%10; if(wei=5) coutwei ”, ”wan” , ”qian ”, ”bai”,”shi ”,” geendl; if(wei=4) coutwei ”, ” qian ” , ” bai ” , ” shi ” , ”geendl; if(wei=3) coutwei ”, ” bai ” , ”shi ”, ” geendl; if(wei=2) coutwei ”, ” shi ”, ” geendl; if(wei=1) coutwei ”, ” geendl; return 0; 11、

17、打印出下列图形(用循环完成) #include using namespace std; int main ( ) int i,j,k; for(i=1;ii;j-) cout ; for(k=1;k=2*i-1;k+) cout * ; coutendl; return 0; 1 1 2 3 4 #include using namespace std; int main ( ) int i,j; for(i=1;i=4;i+) for(j=1;j=i;j+) coutj; coutendl; return 0; 12、将一个一维数组逆序输出 #include using namespace std; int main() int i,a10; for(i=0;i=0;i-) coutai; return 0; 13、求 Fibonacci 数列。 #include using namespace std; int main() int i; int f20=1,1; for(i=2;i20;i+) fi=fi-2+fi-1; for(i=0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论