新手學C語言36實例_第1頁
新手學C語言36實例_第2頁
新手學C語言36實例_第3頁
新手學C語言36實例_第4頁
新手學C語言36實例_第5頁
已閱讀5頁,還剩27頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

目錄..........................................................................................................................11輸入:......................................................................................................................22輸入:......................................................................................................................23求三數(shù)整中最大.................................................................................................24求位數(shù)及每:........................................................................................................35分批發(fā)獎金:............................................................................................................56求方程:...............................................................................................................67求素數(shù):...................................................................................................................78統(tǒng)計字:...............................................................................................................89求水仙花數(shù):............................................................................................................90猴子吃:...........................................................................................................101小球下落:.........................................................................................................112菱形:................................................................................................................113比賽:................................................................................................................134求平均成績:.....................................................................................................135找最高成績:.....................................................................................................146求平均各科成績:..............................................................................................147反排序:............................................................................................................158二分法:............................................................................................................169統(tǒng)計字符:.........................................................................................................180最大公約數(shù)最小公約數(shù)....................................................................................181判斷素數(shù):.........................................................................................................202矩陣轉(zhuǎn)置:.........................................................................................................203字符串反序:.....................................................................................................214排序:................................................................................................................225數(shù)值化為字符串:..............................................................................................236用指針比大小..................................................................................................247一個數(shù)組換首尾:..............................................................................................248字符后移n個單位...........................................................................................259測字符串長:.....................................................................................................260動態(tài)鏈表:.........................................................................................................271起泡法比排序..................................................................................................292求最大公約數(shù)(輾轉(zhuǎn)相減法:...........................................................................303三階矩陣相乘..................................................................................................304選擇法字母排序:..............................................................................................315字符串中挑一類字符:.......................................................................................326四階矩陣計算..................................................................................................32第1頁(共2 )1入#ie<di#ie<#iePI3.26vid){t;dblec,2,1,v2;;css2=4*PI*r*r;;v2=PI*r*r*h;"周面積,球面球,圓柱=%5.2f\n",c,s1,s2,v1,v2);}2入#ie<divid){s,&);c=5*(F-32)/9;"攝氏溫度為%.2f\n",c);}3值#ie<di第2頁(共2 )vid){ita;pnt"Plebc:";sd%d"&&d=(a>b)?a:b;max=(c>d)?c:d;printf("max=%d",max);}4位#nlstdivid){etrsn;;{a[i]=n%10;n=n/10;i++;}while(n>0);"這是一%d位數(shù)\n",i);for(j=i-1;j>=0;j--)printf("%d\t",a[j]);printf("\n");for(j=0;j<i;j++)printf("%d\t",a[j]);printf("\n");}//*****************************************************//*****************************************************#ie<divid)第3頁(共2 ){inta,b,c,d,e,n,num;printf("pleaseenteraintgernumberlessthn100000");saf(nuif(0)n;esei(n00)m;esei(n00)m;esei<100)m=4;elsen=5;printf("Thisis%dcoulmenumber\n",m);a=nub=(num-a*10000)/1000;c=(num-a*10000-b*1000)/100;d=(num-a*10000-b*1000-c*100)/10;e=num%10;if(m>4)printf("fromhightolow:%d,%d,%d,%d,%d\n",a,b,c,d,e),printf("fromlowtohigh:%d,%d,%d,%d,%d\n",e,d,c,b,a);elseif(m>3)printf("fromhightolow:%d,%d,%d,%d\n",b,c,d,e),printf("fromlowtohigh:%d,%d,%d,%d\n",e,d,c,b);elseif(m>2)printf("fromhightolow:%d,%d,%d\n",c,d,e),printf("fromlowtohigh:%d,%d,%d\n",e,d,c);elseif(m>1)printf("fromhightolow:%d,%d\n",d,e),printf("frlowtohin",e,d;eleprit(n",e),printf("%d\n"e}//*****************************************************//*****************************************************#ie<di#ie<vid){intx,a,b,c,d,e,n;scanf("%d",&x);a=(x/10000);b=(x-a*10000)/1000;c=(x-a*10000-b*1000)/100;d=(x-a*10000-b*1000-c*100)/10;e=(x-a*10000-b*1000-c*100-d*10);i)第4頁(共2 )printf("%d%d%d%d%d\n",e,d,c,b,a);elseif(b!=0)n=4,printf("%d,%d,%d,%d\n",b,c,d,e),printf("%d%d%d%d\n",e,d,c,b);eseifc!nprnt%d\nd,,printf("%d%d%d\n",e,d,c);elseif(d!=0)n=2,printf("%d,%d\n",d,e),printf("%d%d\n",e,d);eei(e!0)n,pin%d\n,eprintf("%d\n",e);pntn",;}5金#ie<divid){floatI,s;printf("Pleaseentera's':");scanf("%f",&I);f (I>1000000)s=0.1*100000+0.075*100000+0.05*200000+0.03*200000+0.015*400000+0.01*(I-1000000); f (I>600000)s=0.1*100000+0.075*100000+0.05*200000+0.03*200000+0.01*(I-600000);elseif(I>400000)s=0.1*100000+0.075*100000+0.05*200000+0.03*(I-400000);elseif(I>200000)s=0.1*100000+0.075*100000+0.05*(I-200000);elseif(I>100000)s=0.1*100000+0.075*(I-100000); s=0.1*I;printf("%f\n",s);}//*****************************************************//*****************************************************#ie<di第5頁(共2 )vid){intc;floatI,s;printf("Pleaseentera'I':");scanf("%f",&I);c=I/100000;sth(c){case0:s=0.1*I;break;case1:s=0.1*100000+0.075*(I-100000);break;ca2:ca3:s07(-ca4:ca5:s*0020aca6:cse7:cse8:cse 9 :s=0.1*100000+0.075*100000+0.05*200000+0.03*400000+0.015*(I-600000);break;t :s=0.1*100000+0.075*100000+0.05*200000+0.03*400000+0.015*600000+0.01*(I-1000000);};}6根:#ie<di#ie<vid){flata,b,,x,x1,d,pint(eener'a''b''c':);scan%ff%f",&a,,f{x=-c/b;printf("x=%f\n",x);}eef*a>){b+q)/(;b-sqrtb))/;preleif(b*b-4*a)第6頁(共2 )else{d=-b/(2*a);e=sqrt(4*a*c-b*b)/(2*a);printf("x1=%f+%fi,x2=%f+%fi\n",d,e,d,-e);}/*else{x1=(-b+sqrt(b*b-4*a*c))/(2*a);x2=(-b-sqrt(b*b-4*a*c))/(2*a);pn=nx/}7數(shù):#nlstdi#nde.vid){;f(m=10m){k=srt();fr)iif(i>k) pnt"}}//*****************************************************//*****************************************************#nlstdi#nde.vid){inti,j,m;"全部素數(shù)如:\n");for(i=101;i<201;i++){for(j=2;j<m;j++)if(i%j==0) break;if(j==m)printf("%d\t",i);}}第7頁(共2 )8符:#nlstdivid){itl0;charc;while((c=getchar())!='\n'){if(c>='a'&&c<='z'||c>='A'&&c<='Z')l++;eseif(c>='0'9nelseif')s;elet;}}//*****************************************************//*****************************************************#nlstdivid){itl0;charc;fr;(c=gethar(!='n';){l;eseif(c>='0'9n第8頁(共2 )ef')s;elet;}}//*****************************************************//*****************************************************#nlstdivid){itl0;charc;do{l;eseif(c>='0'9nelseif')s;elet;}hile((cgetcprid,d,n=s,t;}9數(shù)#ie<divid){;fr(=i)第9頁(共2 ){for(j=0;j<10;j++){r){ difd==i*i+j*j+kpr}}}}//*****************************************************//*****************************************************#nlstdivid){;for(i10;ifor(j=0;j<10;j++)for(k=0;k<10;k++)if(i*i*i+j*j*j+k*k*k==i*100+j*10+k)printf("%d\t",i*100+j*10+k);}桃:#ie<divd{itfr(1d--){ ;printf("%d\t",d-1);printf("%d\n",n);}}第0共2 )#imain(){t;fh0010for(n=0;n<11;n++){ s+=2*h;h*=0.5;f %f\n",n+1,s);if(n==10)continue;}}//******************************************************//******************************************************#ie<divd{t;fh0010for(n=0;n<11;n++){ s+=2*h;h*=0.5;f %f\n",n+1,s);if(n==10)break;}}#nlstdivid){;fr(ii;i++){for(j=1;j<8;j++){)";ef;第1共2 )};}r){for(j=1;j<8;j++){)";ef;};}}//*****************************************************//*****************************************************#ie<divid){;fr(ii;i++){for(j=1;j<25-i;j++)pf";for(k=1k*i-1)prntf();prntf(n);}r){for(j=1;j<25-i;j++)pf";for(k=1k*i-1)prntf();prntf(n);}}//******************************************************//******************************************************#ie<divid){itj;fr(i+)第2共2 ){for(j=0;j<=15+i;j++){if(j<15-i)printf("");elseprintf("*");}f}r){for(j=0;j<=15+i;j++){if(j<15-i)printf("");elseprintf("*");}f}}#ie<divd{ ;rr)frn='z'n++)if(l!=n&&m!=n&&m!='x'&&n!='x'&&n!='z')printf("Avs%c;Bvs%c;Cvs%c\n",m,l,n);}#ie<divd{ft[s=0,;t;pif(inttnnmer);第3共2 )fr(=i)sf(,);prntf(");fr(=i)s+=a[i];p=0.s;"平均成績是f\n",p);}#ie<divid){;itj;max(a[0][)?a[0a1];fr(=i)max=(max>a[printf("%f\n",max);fr(=i)if()pif\t",i);/*學生序號從一開始,而成績的數(shù)組從0開始for(j=0;j<9;j++)for(i=0;i<9-j;i++)if(a[i]>a[i+1]){ a[i+1]=a[i];a[i]=t;}fr(=i)printf("%f\t",a[i]);printf("\n");}#ie<divd第4共2 ){ inta[4][4],i,j;fr(ii;i++)for(j=0;j<4;j++)scanf("%d",&a[i][j]);fr(ii;i++){ : ",i+1);for(j=0;j<4;j++)printf("%d\t",a[i][j]);printf("\n");}fr(ii;i++)a3]i][]i]2);fr(ii;i++){ ) ",i+1);ee;for(j=0;j<4;j++)printf("%d\t",a[i][j]);printf("\n");}}#ie<divd{;fr(ii;i++){b;printf("%d\t",a[i]);}ffr(ii;i++){a[i]=b[4-i];printf("%d\t",a[i]);}f}//****************************************************第5共2 )//****************************************************#ie<divid){it,a,i;pif(iutfveintn);fr(ii;i++)s(",]fr(ii;i++)pintf(,"a[];pintf(n"fr(ii;i++){t=a[i];a[i]=a[4-i];a4-]=;}fr(ii;i++)pintf(,"a[];pintf(n"}#nlstdivid){;;;printf("inputx:\n");scanf("%d",&x);strend=14;wle(nd){miifata{ i++;printf("Fitemtisd\a;bre;第6共2 )}{ i++;pifndtenumberisaen;beak;}{ i++;pinf(dthenumbe,itisa%d],beak;}elseif(x>a[mid])end=mid-1;elsestart=mid+1;}if(i)pri"treisntthtnmr.}//******************************************************//******************************************************#nlstdivid){;intx,star,endmid,iprintf("inputx");scanf("%d",&x);strend=14;do{miix=md]||==a[mi-){i++;if(x==a[mid])pint(ndthenumbetisa[%]=,a[mielseprintf("Findthenumber,itisa[%d]=%d\n",mid-1,a[mid-1]);break;}e) end=mid-1;eed;}lar<nd);第7共2 )){i++;printf("Findthenumber,itisa[%d]=%d\n",end,a[end]);}i)pintttnur;}#ie<divd{charst[]8];inti,ja=0b=0,=0;/*a為大寫字母,為數(shù)字,d為空格為其他字/charx;printf("Pleasethreelineswords:\n");fr(ii;i++);fr(ii;i++)fr(j(ri]j)!\;++){if(x>='A'&&x<='Z')a++;elseif(x>='a'&&x<='z')b++;elseif(x>='0'&&x<='9')c++;elseif(x=='')d++;elsee++;}printf("a=%d,b=%d,c=%d,d=%d,e=%d\n",a,b,c,d,e);}#ie<diintmaxint(intaintb);intmiint(nta,intb);vd第8共2 ){intm,n,max,min;scanf("%d%d",&m,&n);mxx;mn=minintpintf("max=%min=%dn"maxmin);}itnt(itintb){inti,c;cfor(i=c;i>1;i--)if(a%i==0&&b%i==0){run;br;}}//***************************************************//***************************************************/intmaxint(intm,ntn){printf("m=%dn=%d\n",m,n);do{;);}while(m!=n);rtnm;}*///****************************************************intmnint(inta,b){inti,c,d;cd=a*b;fri=ci=d;++)ifi){第9共2 )run;br;}}#ie<di#ie<intsushu(nta);vd{intm,c;scanf("%d",&m);c=sushu(m);if(c==1)printf("%disaprimenumber\n",m);fta;}ut){inti,c;c=sqrt(a);for(i=2;i<=c+1;i++)if(a%i==0) return0;return1;}#ie<divid){inta[3][3],i,j,s=0;for(i=0i++)for(j=0;j<3;j++)第0共2 )for(i=0i++){ for(j=0;j<3;j++)printf("%d\t",a[i][j]);printf("\n");};for(i=0i++){ for(j=0;j<3;j++)printf("%d\t",a[j][i]);printf("\n");}}#nlstdi#il<stingh>r;){;gtst0;;;}{inti,t,j;charstr2[100];;;for(i;}第1共2 )//****************************************************//****************************************************#nlstdi#il<stingh>r;){;;;;}){it;;;for(i=0;j>i;i++,j--){;*()=*(st);*;}}#ie<divdbigr(crr]);vd{cr;gets(str);bigger(str);puts(r;}第2共2 )voidbigger(charstr[]){iti,j;for(j=0;j<9;j++)for(i=0;i<9-j;i++)if(str[i]>str[i+1]){ti1];stst]}}#ie<di#il<stingh>voidnintn,harst[);vid){it;cr;pfetr;scanf("%d",&x);num2str(x,str);puts(str);}vdn(ithartr){chars[2];if(n/10==0){;;}{num2str(n/10,str);第3共2 )s[0]=n%10+48;s[1]='\0';strcat(st,s);}}#ie<divd{t;s(",&b,&c);x&,y=&b,=&c;t=(*x<*y)?*x:*y;ifx{;}f;eeify)prf"%d,d,\**y,z);eepntf("d,*x,*z,}#ie<diinputa[0];void(intou[];inti,*,[0];vd{input(a);d(a);output(a);}第4共2 )input(ia[0]){printf"ut10as:\n);for(i10;isanf"i);}voiddeal(int*p){it,;p=a;for=*p,max=;<9{min=(min<*(p+i+1))?min:*(p+i+1);max=(max>*(p+i+1))?max:*(p+i+1);}fr(=i){if(min==*(p+i)){t=*p;*p=min;*}){t=*(p+9);**}}}t{yfor(i10;ipif""a[]);pif"");}移#ie<di第5共2 )d move(int*p1,int*p2,intn,intm);vd{;inti,n,m;ets、'n'andmovingunits'm':\n");scanf("%d%d",&n,&m);pnt("ltens:for(i=0;i<n;i++)scanf("%d",&a[i]);for(i=0;i<n;i++)printf("%d",a[i]);printf("\n");p12=;me2,,m;for(i=0;i<n;i++)printf("%d",a[i]);printf("\n");}d move(int*p1,int*p2,intn,intm){t;for(j=0;j<m;j++)*(p2+j)=*(p1+n-m+j);for(j=0;j<n-m;j++)*(p1+n-1-j)=*(p1+n-m-1-j);for(j=0;j<m;j++)*(p1+j)=*(p2+j);}#ie<diitren(c*p);vid){ith;cra第6共2 )gets(a);ln;pnnle;}intstrlen(char*p){t;r;;}//*****************************************************//*****************************************************#ie<diitren(c*p);vid){ith;cragets(a);ln;pnnle;}intstrlen(char*p){t;r;;}#ie<di#ie<stlbh>e LENsizeof(structstudent)tt第7共2 ){ t;t;scts;vid){t;t;){;) e; *申請不到空/;if(p->num<0)break;p->ntif()head=p;pb->nextp;pb=p;}**/p=head;while(p->next!=NULL){printf("%d,%f\n",p->num,p->score);p=p->next;}pnt("p->num,or*刪除結*/p=head;// pb=head;printf("Pleaseinputthe

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論