资源描述:
《C语言编程样题》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、例题:-1(x<0)y=0(x=0)1(x>0)y=-1;if(x!=0)if(x>0)y=1;elsey=0;错不要被对齐迷惑else与if的配对关系y=-1;if(x!=0){if(x>0)y=1;}elsey=0;对/*binsearch:findxinv[0]<=v[1]<=...<=v[n-1]*/intbinsearch(intx,intv[],intn){intlow,high,mid;low=0;high=n-1;while(low<=high){mid=(low+high)/2;if(x2、if(x>v[mid])low=mid+1;else/*foundmatch*/returnmid;}return-1;/*nomatch*/}for(expr1;expr2;expr3)statement等价expr1;while(expr2){statementexpr3;}循环体由多条语句构成,一定要用花括号括起来,注意空循环不要把循环语句的下一条语句看成是循环体。P69#include/*reverse:reversestringsinplace*/voidreverse(chars[]){intc,i,j;for(i=0
3、,j=strlen(s)-1;i