c试题讲解.pdf_第1页
c试题讲解.pdf_第2页
c试题讲解.pdf_第3页
c试题讲解.pdf_第4页
c试题讲解.pdf_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

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

文档简介

1 2011 CPROG222 C 编程 数组 a 升序 数组 b 降序 要求 合并成为数组 c 升序 include define N 5 define M 8 void fun int a int b int c int i 0 j M 1 k 0 while i 0 c k a i b j a i b j void main int arra N 5 10 15 27 46 arrb M 50 45 42 29 15 8 5 2 int arrc N M k fun arra arrb arrc printf array arra is for k 0 k N k printf d arra k printf narray arrb is for k 0 k M k printf d arrb k printf nresult arrc is for k 0 k N M k printf d arrc k getch CPROG202 C 编程 完成函数 double fun double x int n 使 fun x n cos x 1 x 2 2 x 4 4 x 6 6 可 将main 内 的scanf lf d 屏 蔽 即 scanf lf d n 10 看结果是否为 cos 60degree 0 5 include void main double x int n double fun double x int n 2 printf Please enter x n scanf lf d printf cos lf lf n x fun x n getch double fun double x int n double sum x1 y1 int i fh x1 x x y1 1 2 fh 1 sum 1 for i 1 i n i sum sum fh x1 y1 fh fh x1 x1 x x y1 y1 2 i 1 2 i 2 return sum Cprog232 c 编程 完成函数 int fun int a 使其返回数组 a 内次大的数 include define ROW 9 int fun int a int i t max max2 max a 0 max2 a 1 if max max2 t max max max2 max2 t for i 2 imax2 max2 a i if max2 max 3 t max max max2 max2 t return max2 void main int arra ROW 45 58 78 60 40 20 30 28 31 int max pre i max pre fun arra printf array arra is for i 0 i ROW i printf d arra i printf nmax pre is d max pre getch CMODY202 C 母串中提取一定长度的子串 改好了 输入 welcome 回车 再输入 2 空格 3 回车 得到子串 elc include include void main char str 100 sub 100 int m n len i printf Enter string gets str printf nEnter m n scanf d d len strlen str if m 1 n len printf Can t run with d and d n m n else i 0 while i n sub i str m i 1 i sub i 0 printf sub string is s n sub getch 4 Cmody201 c 改好了 求最大 n 使得 2 2 4 2 6 2 n 2 1000 include include void main int n 0 sum 0 while sum 1000 n n sum n n printf n d n n 2 getch CCon222 c 改好了 要求输入 n 比如 5 输出如下矩阵 n 5 1 2 3 4 5 10 9 8 7 6 11 12 13 14 15 20 19 18 17 16 21 22 23 24 25 include include define M 10 void pnt int a M M int n int i j for i 0 i n i for j 0 j n j if i 2 0 a i j i n j 1 else a i j i n n j printf array a n d is n n for i 0 i n i for j 0 j n j printf 3d a i j 5 printf n void main int a M M int n printf Input n 2 n And n1 include include void main double x int n double fun double x int n printf Please enter x n n scanf lf d printf fun lf n fun x n getch double fun double x int n if n 1 return x 1 fun x n 1 else return x 6 Cmody221 c 结构数组 输出平均分 及最高分的学生姓名 include structurestudent 改为 struct student char name 10 float score void main struct student stu 8 Mary 76 John 85 Tom 81 Susa 87 Wilu 79 Yili 65 Sonmu 73 Lichar 70 int i 0 mrk float total 0 aver max max stu 0 score mrk 0 while imax max stu i score mrk i i 修改为 i aver total 8 printf naver 2f n Best is s n aver stu mrk name getch Ccon191 c 完成填空 输入 a b c 构成三角形 如 3 4 5 回车 面积 12 include include void main float a b c d area printf Please input 3 numbers n scanf f f f if a b c area sqrt d d a d b d c printf area is 2f n area else printf Not Triangle n getch Ccon212 c 填空 a b c 为区间 1 9 内的整数 求满足 a b c a c c 560 的所有 a b c 的组合 include void comb int m int a b c for a 1 a 10 a for b 1 b 10 b for c 1 c 10 2 sqrt 2x 1 with x in 1 10 3 x for x 1 include include double fun float x if x 10 return log 3 x else if x 1 return sqrt 2 x 1 else 8 return fabs x void main float x double y clrscr printf Please input a number n scanf f y fun x printf f 2f 2f n x y getch Cmody222 c 字符串升序 改好了 选择排序 include include define ROW 5 define COL 30 void fun char s COL int n char temp COL int i j for i 0 i n 1 i for j i 1 j0 strcpy temp s i strcpy s i s j strcpy s j temp void main int i char str COL DEF BAEELCS FHIAME CBADF APMAE fun str ROW clrscr for i 0 i ROW i printf s n str i getch 9 Cprog212 c 编程 Fun 统计两个字符串小写字母个数的差 方法 1 include int fun char str1 char str2 int c1 0 c2 0 char p1 str1 p2 str2 while p1 0 if p1 a if rela 0 printf Numbers of Lower char in s Numbers of Lower char in s str1 str2 if rela 0 printf Numbers of Lower char in s Numbers of Lower char in s str1 str2 getch 10 编程 Fun 统计两个字符串小写字母个数的差 方法 2 include int fun char str1 char str2 int c1 0 c2 0 i 0 while str1 i 0 if str1 i a i return c1 c2 Ccon192 c 完成填空 大车 8 吨 中车 3 吨 微车 1 吨 50 车载 100 吨货 总共的方案 include include int fun int big median small n 0 printf big median small n for big 0 big 13 big for median 0 median 2d 2d 2d n n big median small 11 return n void main int num num fun printf n There are d solutions n num getch Cmody191 c 计算 1 到 100 的偶数之和 include include void main int i 1 int sum 0 while i i 100 if i i 2 2 continue sum i printf Sum is d n sum getch Ccon201 c 完成填空 求 100 到 300 之间的 x 使 x 8 5 且 x 7 4 且 x 5 2 include void main int n for n 300 n 100 n if n 8 5 if n 4 7 getch 12 Ccon202 c 完成 Swap 函数 交换 2 个整型变量 如输入 2 3 得到 3 2 include void swap int p1 int p2 int sum sum p1 p2 p1 p2 p2 sum p1 void main int x y printf please input 2 numbers n scanf d d printf nOriginal x d y d n x y swap printf nNow x d y d n x y getch Cmody192 c 将方阵 a 的左下三角 不含主对角线 加 4 右上三角 含对角线 乘 2 include define N 5 void main int a N N i j for i 0 i N i for j 0 j N j a i j i 5 j 11 printf nArray a is n for i 0 i N i for j 0 j N j printf 3d a i j printf n for i 0 i N i for j 0 j i j a i j 4 for i 0 i N i for j i j N j a i j 2 13 printf nArray a is turned n for i 0 i N i for j 0 j N j printf 3d a i j printf n getch Cmody232 c 改好了 1 121 12 898 21 include void main int i j k for k 1 k 9 k for i 0 i 9 k i printf for i 1 i 1 j printf d j printf n getch Cprog221 c f x y y 2 x y x in 1 2 y in 0 6 整数放 arr 0 小数前 2 位放 arr 1 比如输入 1 5 2 则 x 1 5 y 2 f x y 9 0 include include void fun int arr double x int y double t y 2 pow x y arr 0 int t arr 1 int t arr 0 100 14 void main int y double x int arra 2 printf Please enter x 1 x 2 y 0 y1 0 printf npart1 d part2 d arra 0 arra 1 else printf x or y is out of range getch ccon002 c pi 4 1 1 3 1 5 1 7 1 10001 include stdio h main double pi 0 long i sign 1 for i 1 i 10001 i 2 pi 1 0 sign i sign sign pi 4 printf f n pi getch cmody001 c 从字符数组 str1 中取出 ascii 值为偶数且下标为偶数的元素 运行结果 str1 4AZ18c Ge9a0Z t 4z8z include include 15 include include void main char str1 100 t 200 int i j j 0 clrscr strcpy str1 4AZ18c Ge9a0z for i 0 i strlen str1 i if str1 i 2 0 j t j 0 printf n s n str1 printf n s n t getch cmody002 c 2 yuan for cock 1yuan for hen 0 5yuan for chicken How many combinations exist such that cock hen chicken 100 cock 2yuan hen 1yuan chicken 0 5yuan 100yuan include include int fun in

温馨提示

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

评论

0/150

提交评论