



版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
c語言經典例題(Clanguageclassicexamples)writeafunctionandcalltosolveasmallballfromHmetersheightfreefall,eachtimeafterfallingdown,reboundbacktotheoriginalheightofhalf,thenfall,askitintheNlanding,howmanymeters?VoidSM(floats)!Inti;Floath=100;For(i=l;i<=10;i++)IH=h/2;S=s+h*2;)Printf("\nh=%f\ns=%f\n","H","s");Return(s);Floatsum;SM(sum);)writeafunctionandcall,findthesequenceof2/1,3/2,5/3,8/5,13/8.21/13 Findthesumoftheprecedingnitems.Voidsum(floats){Int,a=2,b=l,n=2,t;S=a/b;While(nく=20)(T=a;A=a+b;S=s+(float)a/b;N++;)Printf("\ns=%f\n”,s);Return(s);)(main)IFloatsu;Sum(Su);)writeafunction,askS=a+aa+aaa+aaaa+ +aaa...ItemninAAAA(na),whichcalculatesthevalueofSbycalling.#include<stdio.h>#include<math.h>Int}a,N,t,I,s=0;Sum=O;Scanf(〃%d",〃%d",〃&a","&n");For(i=l;i<=n;i++){T=a*pow(10,(i-1));S=s+t;Sum+=s;)Printf('\nsum4d\n",sum);Return(sum);)(main)Total(Su);writeafunction,fortherootoftheequationax2+bx+c=0,fromthemainfunctioninputa,B,Cvalues.#include<stdio.h>#include<math.h>VoidABC(int,a,int,B,int,c){float,x,I,xl,x2;I=pow(B,2)-4*a*c;If(a==0){x=-(c/b);Printf("x=%f",x);}ElseIf(i〉=0)Xl=(-b+sqrt(I))/(2*a);X2=(-b-sqrt(I))/(2*a);Printf("xl=%.2f","x2=%.2f\n","XI","x2");)ElsePrintf("wrong\n");))(main)(Int,a,B,c;Scanf("%d,%d,%d",&a,&b,&c);ABC(a,B,C);)ヽwriteprograms,calculatethefollowingformulaandoutputtheresult.Requirements:(1)writeafunctiontocalculaten!writethemainfunction,bykeyboardinputnandm,call(1)inthefunctiontocompletethecalculation.enterNandmtogivehints,andcheckthereasonablenessofNandm,unreasonableinputshouldoutputwronginformation,andnolongercalculate.#include<stdio.h>Longpower(intn)ILongf;If(n>l)F=power(n-1)*n;ElseF=1;Return(f);Int,N,m;Longc;Scanf("%d",〃%d",〃&n","&m");If((n-m)>0)(empower(n)//(power(n-m)*power(m));Printf("c=%ld\n”,C);)ElsePrintf("pleaseput,into,new,number,\n");}writeafunction,entera4digitnumber,theoutputofthese4digitalcharacters,buteverytwonumbersemptyaspace.Iftheinputoutputshouldbe1990,"1"9"9"〇”.#include<stdio.h>Charnum(intn)Int,N1,N2,N3,n4;N4=n%10;N3=n/10%10;N2=n/100%10;Nl=n/1000;Printf(%d,%d,%d,%d\n,N1,N2,N3,N4);)(main)Intn;Charnuml;Scanf("%d",&n);Numl=num(n);Printf numl);writeafunctionandcalltodeterminea5digitnumber,isnotpalindromenumber.Thatis,12321isthepalindromenumber,thebitsarethesameasthetens,thetenbitsarethesameasthethousand,andthenprinttheresult.N(int,a){Int,Al,A2,A3,A4,a5;A5=a%10;A4=a/10%10;A3=a/100%10;A2=a/1000%10;Al=a/10000;If(a5==alanda4==a2)Printf(The,num,%d,'huiwen'\n,is,a);ElsePrintf("Itisnot'huiwen'\n");(main)Int,AA,num;Scanf &num);Aa=n(Num);writeafunctionandcall,forafloatingpointnumberhinthevalueof2decimalplaces,andthirdforfourtofiveinto(specifythefloatingpointnumberispositive).Forexample,theHvalueis8.32433,andthefunctionreturns8.32;theHvalueis8.32533,thenthefunctionreturns8.(becausetheprintffunctionitself,whenprinted%.2fcanbefourtofive,theproblemcannotbedirectlyentered,printed,andtheneedtointerceptthenumberofoperations,andthenoutput)#include<stdio.h>Voidn(floata)Int,B,C,e;Floatd;B=(a*100〇)/10;C-b/10;E=b%10;If(e>5)(C-c+1;D=c?〇.01;}ElseD=c?0.01;Printf(the,num,is,%f\n,D);Floata;Scanf &a);N(a);)writeafunctiontochangeacharacterfromitsthirdcharacters(example:entera,becomeC,enterB,d),enteralineofcharactersfromthekeyboard,andconvertbyfunctioncall.#include<stdio.h>VoidCH(charc)(While((c=getchar())-='\n')(If(c〉='a'&&cく='x'c>='A'&&cく='X'II)C=c+2;Elseif(c==,y)||c=='z'||c=='Y'||c=='Z')C=c-24;Printf("祝",C);)Return?;)(main)(Chara;A=getchar();CH(a);)twotabletennisteamcompetition,eachoutof3people.AteamofA,B,C,BteammembersX,Y,Z,havedrawnlotstodecideonthelistofmatches.Someoneaskstheteamforalistofthegames,andAsayshedoesn'tplaywithX.Csayshedoesn'tplaywithXorZ.Pleaseprogramtofindalistofthe3matchplayers.Char,jia[3]={'A','B','C'};Char,yi[3]={'X','Y','Z'};Int,I,j;Printf("\nthelistis:\n");For(i=0;i<3;i++)For(j=0;j<3;j++)If(i==0j==2IIi==2j==0i==2||&&&&&&j==2)JElsePrintf("%c:%c\n”,jia[i],yi[j]);)n(n>3)personalcircle,orderarranging.Fromfirsttostartoff(from1to3report),whoreported3peopleoutofthecircle,leavingthelastquestionistheoriginalnumber.Thevalueofnisenteredfromkeyboard.Inta[50];Int,I,N,num,counter;Printf("\nPleaseinputn:\n");Scanf &n);For(i=l;i〈=n;i++)1=1,num=0,counters;While(counter>l)[If(i==n+l)1=1;If(a[i]==l)Num++;If(num==3)A[i]=0,num=0,counter一;For(i=l;i<=n;i++)If(a[i]==l)Printf(\nThe,last,one,is,%d\n,No.,I);)Enterastringandcopytheuppercaseletterstoanotherstring.(main){char,strl[50],str2[50];Int,i=0,j=0;Printf("\npleaseinputastring:\n");Scanf("%s”,&strl);While(strl[i],=‘、〇'){if(strl[i]>='A'andstrl[i]く='Z'){str2[j]=strl[i];J++;1++;)Str2[j]='\0';Printf(\nthe,first,string,is:%s\nthe,second,string,is:%s\n,STR1,STR2);)pocketred,green,white,black,4colorsoftheballafew.Eachtimeyoutake2ballsoutofyourpocket,askforthepossibilityofgetting2differentcolors,andoutputeachpermutation.(main){int,Bl,B2,num=0;Printf("num\tballl\tball2:\n");For(bl=l;blく=4;bl++)For(b2=l;b2く=4;b2++)If(B2,=bl){num++;Printf("%d\t",num);Switch(Bl){case1:printf("red\t");break;Case2:printf("green't");break;Case3:printf("white't");break;Case4:printf("black't");break;)Switch(B2){case1:printf("red't");break;Case2:printf("green't");break;Case3:printf("white't");break;Case4:printf("black't");break;Printf("\n")Printf("\ntotal:%d\n”,num);Getch();)aboutprimenumbers.enteranumbertodeterminewhetheritisaprimenumberornot.#include<math.h>#includesstdio.h><sushu(intm)Iinti,k;printf("pleaseinputnumberbiggerthanzero:");scanf("%d",a&m);k=(int)sqrt(m).for(i=2;the<=k;i++)if(m%i==0)break;if(i>k)printf("%dissushu\nm).elseprintf('%disn'tsushu\n',m).)main()(intnum;sushu(num);}(2)、求n以內所有的素數.#includesmath,h><
#includesstdio.h><sushu(intn)inti,k,m=1.printf("ヽprintf("ヽnpleaseinputnumberbiggerthanone:");scanf("%d",&n).for(m=1,m<=n;m++)k=(int)sqrt(m).for(i=2;the<=k;i++)if(m%i==0)break;if(i>k)printf("%d\t"m);elsem++;main()!intnum;sushu(num);)15、現有一個整數數組,其中的元素按照從小到大的順序已經排好序,現再輸入ー個數,要求按原來的規(guī)律將它插入數組中.(注意:插入數的時候,需要將要插入位置及以后的內容向后移動ー個位置,空出當前位置放置新的數值)main()(int[11]1,4,6,9,13,16,19,28,40100-{};inttempi,temp2,number,end,i,j;printf(originalarrayis:\n);for(i=0;i<10;i++)printf("%5d",[]);printf("ヽn");printf(insertanewnumber:,z);scanf("%d”,&number);end=[9].if(number>end)in[10]=number;elsefor(i=0;{<10;i++){if(a[i]>number){tempi=a[i].[i]=number;for(j=i+1,j<11;j++)temp2=a[j].a[j]=tempi;tempi=temp2;}break;)))for(i=0;i<11;i++)printf("%6d",[]);)16、輸入行數,打印n行的ー個由數字組成的三角形,三角型如下11211232112345654321123456765432112345678765432112345678987654321#includesstdio.h>くmain(){intn,i,j;scanf("%d”,&n).for(i=1,theく=n;i++)for(j=1;j<=n-1;j++)printf(つ.for(j=1;j<=i;j++)printf("%d”,j).for(j=1;j>0;i—)printf("%d”,j).printf("ヽn");))17、編寫ー個函數,輸入n為偶數時,調用函數求1/2+1/4+...+1/n,當輸入n為奇數時,調用函數1/1+1/3+...+1/nfl(intx)[floaty=0;inti;if(x!=1)if(x%2==0)for(i=1;i<x;i++)d=s+1.0/(2*);)if((x%2).=0&&x!=1)!for(i=1;i<x;i++)d=s+1.0/(2*1).))elsed=1;printf("thetotalis$.2f\n",s);main()intn;printf("ヽnpleaseinputsthenumberis").scanf("%d",&n).fl(n).)18、編寫ー個函數,分別對整型數組的下標為偶數的元素和下標為奇數的元素求和main(){inti,js=0,f=0.intarr[10]={1,2,3,4,5,6,7,8,9,10);for(i=0;i<10;i++)if(i%2==0)os=os+arr[i].elsejsjs+=arr[i].printf("\njs=%dos=%d",js,os).19、編寫ー個程序,實現兩個字符串的連接includesstdio.h><main(){charal[50],a[50].inti,j;printf
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 外墻冬季施工方案
- 防滑地磚樓面施工方案
- 2025年天津法檢筆試試題及答案
- 2025年找貨運司機面試題及答案
- 低利率時代的投資和資產配置策略
- 噴射砂漿加固施工方案
- 清理植被灌木施工方案
- 鋼構的施工方案
- 2025年唐山工業(yè)職業(yè)技術學院單招職業(yè)適應性測試題庫參考答案
- 2025年山東省濱州地區(qū)單招職業(yè)適應性測試題庫新版
- DB43∕T 801-2013 二次張拉低回縮鋼絞線豎向預應力短索錨固體系設計、施工和驗收規(guī)范
- 附表1:網絡及信息安全自查表
- 奇妙的海洋生物
- 精裝修工程一戶一驗記錄表
- 公共場所健康證體檢表
- 普通高等學校獨立學院教育工作合格評估指標體系(第六稿)
- 哈薩克斯坦共和國有限責任公司和補充責任公司法
- 多維閱讀第13級—A Stolen Baby 小猩猩被偷走了
- 三愛三節(jié)-主題班會
- 2018版公路工程質量檢驗評定標準分項工程質量檢驗評定表交通安全設施
- (完整版)電機學第五版課后答案_(湯蘊璆)
評論
0/150
提交評論