(C语言课件)第七章数组.ppt

  1. 1、本文档共71页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
例5 输入30名学生的学号和一门课的成绩,将高于平均分的学生的学号和成绩打印出来。 main() { static char num[30][7]; float s[30], avg, sum; for(i=0;i30;i++) scanf(“%s,%f”,num[i], s[i]); sum=0.0; for(i=0;i30;i++) sum+=s[i]; avg=sum/30; for(i=0;i30;i++) if(s[i]=avg) printf(“%s, %f”,num[i],s[i]); } 例6 用顺序查找的方法查找某数。 main() { int a[20],x,p,i; printf(“input numbers:\n”); for(i=0;i20;i++) scanf(“%d”,a[i]); printf(“enter a number for serch:”); scanf(“%d”,x); p=0; while(x!=a[p]p20) {p=p+1;} if(x==a[p]) printf(“%d ,%d”,x,p); else printf(“%d could not be founded”, x); } 例7 用折半查找的方法查找某数。 main() {int a[20],top,bot,mid,p,x,i,find=0; printf(“input numbers:\n”); for(i=0;i16;i++) scanf(“%d”,a[i]); printf(“enter a number for serch:”); scanf(“%d”,x); find=0; top=1; bot=15; while(top=bot!find) { mid=(top+bot)/2; if(x==a[mid]) {find=1; printf(“%d has e founded on %d the position:”,x,mid); } else if(xa[mid]) bot=mid-1; else top=mid+1; } if(!find) printf(“%d could not be founded”,x); } 例8 选择法排序 用选择法对数组中5个整数由小到大排序,方法是:无在a[0]~a[4]中找出最小数与a[0]对换,再在a[1]~a[4]中找最小数与a[1]对换 ...... void sort(b, n) int b[ ], n; {int i, j, k, t; for(i=0;in-1; i++) {k=i; for(j=i+1; jn; j++) 地址 前 后 if(b[j] b[k]) k=j; t=b[k]; b[k]=b[i]; b[i]=t; } ffcc 3 -1 a[0] b[0] for(i=0;in;i++) ffce 2 2 a[1] b[1] printf(“b[d]=%x,b[%d]=%d\ n”, i, b[i], i, b[i]);} ffd0 -1 3 a[2] b[2] main( ) ffd2 8 6 a[3] b[3] {int a[5], i; printf(“enter the array a:\ n”); ffd4 6 8 a[4] b[4]

您可能关注的文档

文档评论(0)

autohhh + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档