C++练习题及答案.pdf_第1页
C++练习题及答案.pdf_第2页
C++练习题及答案.pdf_第3页
C++练习题及答案.pdf_第4页
C++练习题及答案.pdf_第5页
已阅读5页,还剩29页未读 继续免费阅读

下载本文档

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

文档简介

1 A A+B Problem B 按要求输出 C C 语言实验Hello World!(printf 练习) D C 语言实验图形输出(字符常量练习) A Description Calculate a+b #include using namespace std; int main() int a,b; cin a b; cout a; coutc; c-=32; coutab; coutai; if(ai=1) c=c+1; cout c1 c2 c3 c4 c5; c1 += 4; c2 += 4; c3 += 4; c4 += 4; c5 += 4; cout max d b d c; if (max a; if (a0) if (a = 0; j-) printf(“%d “, aj); printf(“n“); for (j = 0; ja; if(aa; b=a/5; c=b/20; d=b%20; e=d/5; f=b+c*5+e; coutn; m=10000*pow(1.06,n); coutn; for(i=1;iai; for(i=0;i ai; for (i = 7; i = 2; i-) cout n; for(i=0;iai; for(j=0;j=0;i+) if(ai=0)break; if(ai=A puts(a); 1901 Problem A 简单密码破解 1998 Problem B C 语言实验删除指定字符 1919 Problem C 两数组最短距离 2525 Problem D JK 学院的期中测试 B Description 从键盘输入一个字符串给 str 和一个字符给 c,删除 str 中的所有字符 c 并输出删除后的字符串 str。 Sample Input sdf$sdf$ $ Sample Output sdfsdf #include int main() char str120, str220, c; int i = 0, j = 0; gets(str1); scanf(“%c“, while (str1i != 0) if (str1i != c) str2j = str1i; j+; i+; str2j = 0; puts(str2); return 0; D Description 英语有 25 道选择题,每道题 2 分,数学有 25 道判断 题,每道题 2 分。输出成绩 Input 第一行,学生做的英语选择题的答案,由字母(abcd)组成 第二行,英语选择题的标准答案 第三行,学生做的高数判断题的答案,由字符(tf)组成 第四行,高数判断题的标准答案 Sample Input abcdabcdabcdabcdabcdabcda abcdabcdabcdabcdabcdabcdb tftftftftftftftftftftftft tftftftftftftftftftftftff Sample Output 96 #include #include using namespace std; int main() int i,x=0,y=0; char a26,b26,c26,d25; cinabcd; for(i=0;i m n; for (i = 0; i ai; for (i = 0; i bi; min = fabs(b0 - a0); for (j = 0; jlw; c=(l+20)/(w+20); coutai; if(a3=a1+a2) j+; if(a4=a1-a2) j+; if(a5=a1*a2) j+; if(a6=a1/a2) j+; coutai; max=a1; for(i=2;iai)?max:ai; coutab; if(aabcdefghij; if(an; flag=is_prime(n); if(flag=1) coutGF; coutabc; sum=fac(a)+fac(b)+fac(c); coutai; coutn; int i=n,a100; for(i=0; iai; SelectionSort(a,n); for(i=0; in; digui(n); return 0; void digui(int t) int i=0,x=t; char a20; while(x=1) ai=x+48; i+; x-; while(xi; couti; couta; coutgold; coutstr; int len; len=strlen(str); int fuction(char *, int); fuction(str,len); return 0; int fuction(char *p, int n) char *q; for(q=p+n-1;q=p;q-) cout= A else t+; printf(“%dn%dn%dn%dn%dn“, j, x, y, t, j + x + y + t); 2568 Problem A 字符串逆序输出 2569 Problem B 统计字符串种类 2570 Problem C 指针练习变量交换 2571 Problem D 指针练习求字符串长度 C Description 指针的功能多种多样,指针是 c 语言的灵魂,所以说掌握 指针是很重要的。 下面要求你用指针实现两个数字的交换 Input 两个 int 型的变量 Output 交换后的两个变量 Sample Input 1 2 Sample Output 2 1 #include using namespace std; int main() int a,b; int *c= void exc(int*,int*); cinab; exc(c,d); couta; void MyStrlen(char *pa); MyStrlen(a); return 0; void MyStrlen(char *pa) char *x; int i; x=pa; for(x=pa,i=0;*x!=0;x+,i+) ; coutdate.yeardate.monthdate.day; day_sum=days(date); coutn; for(i=0;istui.num; ; for(j=0;jstui.scorej; for(i=0;ia.heada.pointa.tail; cinb.headb.pointb.tail; add(a,b); return 0; D Description 分数可以看成是由字符/分割两个整数构成,可以用结构 体类型表示。请用结构体类型变量计算两个分数的差。 注意:不考虑约分,只考虑大数减小数,分母相同的情 况。 Sample Input 2/7 1/7 Sample Output 1/7 #include using namespace std; struct fenshu

温馨提示

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

评论

0/150

提交评论