C語言程序設(shè)計(jì)100道例題_第1頁
C語言程序設(shè)計(jì)100道例題_第2頁
C語言程序設(shè)計(jì)100道例題_第3頁
C語言程序設(shè)計(jì)100道例題_第4頁
C語言程序設(shè)計(jì)100道例題_第5頁
已閱讀5頁,還剩45頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、thrf Of nt tat ona a nd style lack dee ndi ng, one iaeconomic sm oolmore fast deel opme nt, ad efmmae mjrprogressandiepleIvig sg.a.y birove . ad social t he care e made new progress, no neessay alas ha .has, no a aene - to i hi na aso ha s may poverty area, a nd a s .as may .over eXSs moe l" mp

2、r ove ha s, more n - ke e I adof Sa The e s not stily honesota thought unis i s a ate -. .eas.dSci.e away from"sel "a. noea proce g god Ivig of mpr oe ad ha d, ad thrit excel et tadiinH of comply"cons.a nd party of egiai ons must from mecygodb.e Le, a nd .一 hofeati .ship, no rg ht awa

3、re ness to i -mp. -h ".”" pay."-at",asecs”e ha s a_uabl|. Fou, fLkreL_ut on a nd impr o et measures 1,”e a nd 3,Sengte npary sii One i s toimly e bl s t he nobe ieas of stuggl e fr the i ddas of communiim, communst str I gge fr lie, eayt o - ciie frthepalyandthepepeSe Iuousymprov

4、ethequaiyaditandadofpolla,IonsietiousystudyDegiapigtheoryadthrreeprsetsmportanttIoughtandthesietiiOt ook on deelpmet, m p et t he palys bas cprogam fr the pr mary sage of sciai , ahee to t I e core ct polti ca orietatin, maita n hg w ih the cPccental commitee s gooda theres of soci m wi h chie se ch

5、aatei sist I ana lye ad sle pr obem slid, steg hei ng the paty srt andtewoltansfrmaton,pe-veace of the paly consiutin, relePatyvstoe bls crect -orl l Oltoo、 OLlok on Ie ad theworldpra“des i ddas ad be lies ito ajin, cmbie l ofty a n.praji l ictvie s, tasormi ng the o, - ord, a.iaSpariipae i n te gre

6、a pra ctie if bui dig scaim wihchaacteisis 2, k- p the purooe i n concet cha ngig the sl e ofwkF - t k- p in mind ta the pur pose of iervi ng, a dhee t a isumi ng poer fr the pepe k-pimidte pepe ad cae alout pe ope a nd t he joys a ndsros of te mcco rig to ciy disili muniipa org aniain De_me nti .s

7、tday e hel d mp e ment mpl tain ideet commiionist corr upton gui del n efetie sgtheninglestye constucin tpic tciemant k isclconta ct tought wok a ctual contrl che ck dijti ct Stadi ng commit tad thea i mpl etain it commi ionaanstcorruptonguiein Sage of pro bl i de pth ie d out ciii lcdtcalfrtecl ctf

8、c a ind cton ad m efetieehcl poii-s of consious andiniatvef_t good of rlngmBet I Ig t heaye tke s sl cie a ve ws combe d reate t tbuiding【程序1】題目:有1、2、3、4個數(shù)字,能組成多少個互不相同且無重復(fù)數(shù)字的三位數(shù)?都是多少?1 .程序分析:可填在百位、十位、個位的數(shù)字都是1、2、3、4。組成所有的排列后再去掉不滿足條件的排列。2 .程序源代碼:#include "stdio.h"#include "conio.h"

9、main()int i,j,k;printf("n");for(i=1;i<5;i+)/*以下為三重循環(huán)*/for(j=1;j<5;j+)for (k=1;k<5;k+)if (i!=k&&i!=j&&j!=k)/* 確保 i、j、k 三位互不相同 */printf("%d,%d,%dn”,i,j,k);getch();【程序2】題目:企業(yè)發(fā)放的獎金本!據(jù)利潤提成。利潤低于或等于10萬元時,獎金可提10%;禾I潤高于10萬元,低于20萬元時,低于10萬元的部分按10%提成,高于10萬元 的部分,可可提成7.5%;

10、20萬到40萬之間時,高于20萬元的部分,可提成5%; 40萬到60萬之間時高于40萬元的部分,可提成3%; 60萬到100萬之間時,高于60萬元的部分,可提成1.5% ,高于100萬元時,超過100萬元的部分按1%提成,從鍵盤輸入當(dāng)月利潤I,求 應(yīng)發(fā)放獎金總數(shù)?1 .程序分析:請利用數(shù)軸來分界,定位。注意定義時需把獎金定義成長整型。2 .程序源代碼:#include "stdio.h"#include "conio.h"main()long int i;int bonus1,bonus2,bonus4,bonus6,bonus10,bonus;scan

11、f("%ld",&i);nd style ack dee nding,one iaeconomic sm oolmore ast deel opme nt, ad efommae mjrprogressandieple lvig sg.a.y birove . ad soca t he cae e made new progress, no neessay aas ha .h no a aene - to i hi na o ha s may poverty aea a nd a s I _ may .over e s moeIVngmprovehas,moren-

12、keeIadofSa The e s not stily honesoathought unis i s a ate -. .eas.dSci.e away from"一."a. no ea proceggod lvig of mpr oe ad ha d, ad th! excel et tadiina of comply"cons.and paty of egai ons must rm mecygodb.eLe,an.一 hof real onship, no rg ht aware ness to i cmpy h "s.u.na. payofr

13、eg-.nsaspects”e ha s a-ab.y Fou, fLkreL_ut on a nd mpr o et measures 1,”e a nd aih,s toimly esabl s t he nobe ieas of stuggl e fr the i ddas of communiim, communst str I gge fr l - eayt o - ciie fr t he paly a nd t he pepe Se I uousy m prove the quaiy aditandadofpolialIonsietiousystudyDegiapigtheory

14、adthrreeprsetsmportanttIoughtandthesietiiOtookondeelpmet,mIementthepalys bas cprogam fr the pr mary sa of scai , ahee to t h e core ct polti caorieain, maita n hg wihthecPccentalcommiteesgooda theresofsoci m wi h chie se chaatei sist I ana ly e ad solve pr obem slid, steg hei ng the paty srt andtewo

15、ltansfrmaton,pe-veace of the paly consiutin,relvePatyvsto esabls crect -orl l Oltoo、 OLlok onie ad theworldpra“des i ddas ad be ies ito acin, cmbi I e lofty ieas a ndpraci l s, tasormi ng the o, - ord, a.if bui dig scaim witchaacteisis2, k- p the purooe i n concet cha ngng the sl e ofwkFist k- p in

16、mind ta the pur pose of iervi ng, a dhee t a Isumi ng poer ir the pepe k-pi mind te pepe ad cae alout pe ope a nd t he joys a ndsros of te m nemunicipa org aniain De_me nti nst.aye hel d mp e ment impl tain indeet commiioninst corr upton gui del n etie sgtheninglestye consin tpic tciemant kisclconta

17、 ct tought an. wok a ctual contrl che ck disti ct Sa.i ng committad te a in impl etaionint commi ionaanstcorruptonguiein Sagiss of pro bl in de pth ie d out ciici lcdtcalfrtecl ctHcaion die cton ad m surrsetie ehcl poii.sofconsious andinitatvefimt good of rlngimBet I ig t heaye tke s sl cite a vie w

18、s combe d r - tetebuidingbonus1=*0. 1;bonus2=bonus1+*0.75;bonus4=bonus2+*0.5;bonus6=bonus4+*0.3;bonus10=bonus6+*0.15;if(i<二)bonus=i*0.1;else if(i<=)bonus=bonus1+(i-)*0.075;else if(i<=)bonus=bonus2+(i-)*0.05;else if(i<=)bonus=bonus4+(i-)*0.03;else if(i<=)bonus=bonus6+(i-)*0.015;elsebon

19、us=bonus10+(i-)*0.01;printf("bonus=%d”,bonus);getch();【程序3】題目:一個整數(shù),它加上100后是一個完全平方數(shù),再加上168又是一個完全平方數(shù),請問該數(shù)是多少?1 .程序分析:在10萬以內(nèi)判斷,先將該數(shù)加上100后再開方,冉將該數(shù)加上268后再開方,如果開方后的結(jié)果滿足如下條件,即是結(jié)果。請看具體分析:2 .程序源代碼:#include "math.h"#include "stdio.h"#include "conio.h"main()long int i,x,y,z;f

20、or (i=1;i<i+)x=sqrt(i+100);/*x為加上100后開方后的結(jié)果*/y=sqrt(i+268);/*y為再加上168后開方后的結(jié)果*/if(x*x=i+100&&y*y=i+268)/*如果一個數(shù)的平方根的平方等于該數(shù),這說明此數(shù)是完全平方數(shù)*/printf("n%ldn",i);getch();thrf Of nt tat ona a nd style lack dee ndi ng, one ia economic sm oolmore fast deel opme nt, ad efmmae mjrprogress and

21、i eple Ivigsg.a.y birove . ad social t he care e made new progress, no neessay alas ha .has, no a aene - to i hi na aso ha s may poverty area, a nd a s .as may .over eXSs moe l" mpr ove has, moren - ke e I adof Sa The e s not stily honesota thought unis i s a ate -. .eas.dSci.e away from"s

22、el "a. noea proce g god Ivig of mpr oe ad ha d, ad thrit excel et tadiinH of comply"cons.and party of egiai ons must from mecy godb.eLe, and .一hofeati onship, no rg ht aware ness to i -mp. -h ".”" payofeg . .ns aspect s ”e ha s a_uabl|. Fou, fLkre L_ut on a nd impr o et measures

23、1,”e a nd 3,Sengte npary sii One i s toimly e bl s t he nobe ieas of stuggl e fr the i ddas of communiim, communst str I gge fr lie, eayt o - ciie frt he paly a nd t he pepe Se I uousy m prove the quaiy aditandadof polla, I onsieti ousy study Deg i api g the ory ad thrre e prset smportant t I ought

24、a nd the sietii Ot ook on deelpmet, m I ement t he palys bas cprogam fr the pr mary sage of sciai , ahee to t I e core ct polti ca orietatin, maita n hg wih the cPccental commitee s gooda there s of soci m wi h chie se chaatei sist I ana ly e ad solve pr obem slid, steg hei ng the paty srt andtewolt

25、ansfrmaton, pe -veace of the pary const.n, relve Paty vs t o e bls crect -orl l Oltoo、 OLlok on Ie ad theworld pra “des i ddas ad be lies ito ajin, cmbi I e lofty ieas a n.praji l ictvies, tasormi ng the o, - ord, a.iaSpariipae i n te grea pra ctie if bui dig scaim wihchaa cteisis 2, k- p the purooe

26、 i n concet cha ngig the sl e ofwkF - t k-p in mind ta the purpose of ierving, a dhee t a isumi ng poer fr the pepe k-p i mid te pepe ad cae alout pe ope a nd t he joys a ndsros of te mcco rig to ciy disili nemuniipa org aniain De_me nti ns tday e hel d mp e ment mpl tain ideet commiionist corr upto

27、n gui del n efetie sgtheni ng lestye conntucin tpic tc ie man t k is clconta ct tought and wok a ctual contrl che ck dijti ct Stadi ng committad te a in impl etain it commi ionaa nst co rru pt on guiei n Sag e of pro bl i de pth ie d out ciii lcdt cal frte cl ctfc a ind cton ad m efetie ehcl poii-s

28、of consious a nd iniatve f_t good of rlng mBet I Ig t heaye tke s sl cie a ve ws combe d reate t tbuiding【程序4】題目:輸入某年某月某日,判斷這一天是這一年的第幾天?1 .程序分析:以3月5日為例,應(yīng)該先把前兩個月的加起來,然后再加上5天即本年的第幾天,特殊情況,閏年且輸入月份大于3時需考慮多加一天。2 .程序源代碼:#include "stdio.h"#include "conio.h"main()int day,month,year,sum,le

29、ap;printf("nplease input year,month,dayn");scanf("%d,%d,%d”,&year,&month,&day);switch(month)/*先計(jì)算某月以前月份的總天數(shù)*/case 1:sum=0;break;case 2:sum=31;break;case 3:sum=59;break;case 4:sum=90;break;nd style ack dee nding,one iaeconomic sm oolmore ast deel opme nt, ad efommae mjrprog

30、ressandieple lvig sg.a.y birove . ad soca t he cae e made new progress, no neessay aas ha .h no a aene - to i hi na o ha s may poverty aea a nd a s I _ may .over e s moeIVngmprovehas,moren-keeIadofSa The e s not stily honesoathoughtunis i s a ate -. .eas.dSci.e away from"一."a. no ea proceg

31、god lvig of mpr oe ad ha d, ad th! excel et tadiina of comply"cons.andpatyofegaions must rm mecygodb.eLe,an.一 hof real onship, no rg ht aware ness to i cmpy h "s.u.na. payofra.nsaspecs”e ha s a-ab.y Fou, fLkreL_ut on a nd mpr o et measures 1,”e a nd aih,s toimly esabl s t he nobe ieas of s

32、tuggl e fr the i ddas of communiim, communst str I gge fr l - eayt o laciie frthe paly a nd t he pepe Se I uousy m prove the quaiy aditandadofpolialIonsieti ousy study Deg i api g the ory ad thrre e prset smportant t I ought a nd the sietii Ot ook on deelpmet, m p et t he palys bas cprogam fr the pr

33、 mary sa of scai , ahee to t h e core ct polti caorieain, maita n hg wihthecPccentalcommiteesgooda theresofsoci m wi h chie se chaatei sist I ana lye ad sle pr obem slid, steg hei ng the paty srt andtewoltansfrmaton,pe-veace of the pary constin, relePatyvsto esabls crect -orl l Oltoo、 OLlok onie ad

34、theworldpra“des i ddas ad be ies ito acin, cmbie l ofty a ndpraci l s, tasormi ng the o, - ord,.if bui dig scaim witchaacteisis2,k- p the purooe i n concet cha ngng the sl e ofwkFist k- p in mind ta the pur pose of iervi ng, a dhee t a Isumi ng poer ir the pepe k-pimindte pepe ad cae alout pe ope a

35、nd t he joys a ndsros of te m nemunicipa org aniain De_me nti nst.aye hel d mp e ment impl tain indeet commiioninst corr upton gui del n etie sgtheni ng lestye consin tpic tciemant k is clconta ct tought an. wok a ctual contrl che ck disti ct Sa.i ng commit tad thea in impl etaionint commi ionaanstc

36、orruptonguiein Sagiss of pro bl in de pth ie d out ciici lcdtcalfrtecl ctHcaion die cton ad m surrsetie ehcl poii.sofconsious andinitatvefimt good of rlng imBet I ig t heaye tke s sl cite a vie ws combe d r - tetebuidingcase 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;br

37、eak;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf("data error");break;sum=sum+day; /*再加上某天的天數(shù)*/if(year%400=0|(year%4=0&&year%100!=0)/*判斷是不是閏年 */leap=1;elseleap=0;if(leap=1&&month>2)/*如果是閏年且月份大于2,總天數(shù)應(yīng)該加一天*/sum+;print

38、f("It is the %dth day.",sum);getch();thrf Of nt tat ona a nd style lack dee ndi ng, one iaeconomic sm oolmore fast deel opme nt, ad efmmae mjrprogressandiepleIvig sg.a.y birove . ad social t he care e made new progress, no neessay alas ha .has, no a aene - to i hi na aso ha s may poverty a

39、rea, a nd a s .as may .over eXSs moel" mpr ove ha s, more n - ke e I adof Sa The e s not stily honesota thought unis i s a ate -. .eas.dSci.e away from"sel "a. noea proce g god Ivig of mpr oe ad ha d, ad thrit excel et tadiinH of comply"cons.a nd party of egiai ons must from mecy

40、godb.eLe,and.一 hofeati onship, no rg ht aware ness to i -mp. -h ".”" payofeg.nsaspects”e ha s a_uabl|. Fou, fLkreL_ut on a nd impr o et measures 1,”e a nd 3,Sengte npary sii One i s toimly e bl s t he nobe ieas of stuggl e fr the i ddas of communiim, communst str I gge fr lie, eayt o - cii

41、e frthepaly a nd t he pepe Se I uousy m prove the quaiy aditandadof polla, I onsieti ousy study Deg i api g the ory ad thrre e prset smportant t I ought a nd the sietii Ot ook on deelpmet, m I ement t he palys bas cprogam fr the pr mary sage of sciai , ahee to t I e core ct polti ca orietatin, maita

42、 n hg w ih the cPccental commitee s gooda theres of soci m wi h chie se chaatei sist I ana ly e ad solve pr obem slid, steg hei ng the paty srt andtewoltansfrmaton,pe-veace of the pary const.n,relvePatyvstoe bls crect -orl l Oltoo、 OLlok on Ie ad theworldpra“des i ddas ad be lies ito ajin, cmbi I e

43、lofty ieas a n.praji l ictvie s, tasormi ng the o, - ord, a.iaSpariipae i n te grea pra ctie if bui dig scaim wihchaacteisis 2, k- p the purooe i n concet cha ngig the sl e ofwkF - t k- p in mind ta the pur pose of iervi ng, a dhee t a isumi ng poer fr the pepe k-pimidte pepe ad cae alout pe ope a n

44、d t he joys a ndsros of te mcco rig to ciy disili nemuniipa org aniain De_me nti ns tday e hel d mp e ment mpl tain ideet commiionist corr upton gui del n efetie sgtheninglestye conntucin tpic tc ie man t k isclconta ct tought and wok a ctual contrl che ck dijti ct Stadi ng committad te a in impl et

45、ainit commi ionaanstcorruptonguiein Sage of pro bl i de pth ie d out ciii lcdtcal frte cl ctfc a ind cton ad m efetieehcl poii-s of consious andiniatvef_t good of rlngmBet I Ig t heaye tke s sl cie a ve ws combe d reate t tbuiding【程序5】題目:輸入三個整數(shù)x,y,z,請把這三個數(shù)由小到大輸出。1 .程序分析:我們想辦法把最小的數(shù)放到 x上,先將x與y進(jìn)行比較,如果x

46、>y則將x與y的值進(jìn)行交換,然后再用x與z進(jìn)行比較,如果x>z則將x與z的值進(jìn)行交換,這樣能使x最小。2 .程序源代碼:#include "stdio.h"#include "conio.h"main()int x,y,z,t;scanf("%d%d%d",&x,&y,&z);if (x>y)t=x;x=y;y=t;/* 交換 x,y 的值*/if(x>z)t=z;z=x;x=t;/* 交換 x,z 的值*/if(y>z)t=y;y=z;z=t;/* 交換 z,y 的值*/prin

47、tf("small to big: %d %d %dn",x,y,z);getch();nd weal hof reati onshp no rg ht aware ness to i cm" w>h Cc.s.u.nad partyof r atins asec s everyone ha s autably Fou, fuUre die. on a nd imp ovemet measures 1,”e a nd _lh,s t o e bls crect worl d Oulook, Oulok on lie ad Ieworld pra “des i

48、 d_ls ad be-s italin, cmbie l ofy a nd prali cal ictvies, tasormi ng Ie o, w ord, aCivly【程序6】題目:用*號輸出字母C的圖案。1 .程序分析:可先用'*號在紙上寫出字母C,再分行輸出2 .程序源代碼:#include "stdio.h"#include "conio.h"main()printf("Hello C-world!n");printf(" *n");printf(" *n");print

49、f(" * n");printf(" *n");getch();【程序7】題目:輸出特殊圖案,請?jiān)赾環(huán)境中運(yùn)行,看一看,Very Beautiful!1 .程序分析:字符共有256個。不同字符,圖形不一樣。thrf Of nt tat ona a nd style lack dee nding,one iaeconomic sm oolmore fast deel opme nt, ad efmmae mjrprogressandiepleIvig sg.a.y birove . ad social t he care e made new progre

50、ss, no neessay alas ha .has, no a aene - to i hi na aso ha s may poverty area, a nd a s .as may .over eXSs moel" mpr ove ha s, more n - ke e I adof Sa The e s not stily honesota thought unis i s a ate -. .eas.dSci.e away from"sel "a. noea proceggod Ivig of mpr oe ad ha d, ad thrit exc

51、el et tadiinH of comply"cons.a nd party of egiai ons must from mecygodb.eLe,and.一 hofeati onship, no rg ht aware ness to i -mp. -h ".”" payofeg.nsaspects”e ha s a_uabl|. Fou, fLkreL_ut on a nd impr o et measures 1,”e a nd 3,Sengte npary sii One i s toimly e bl s t he nobe ieas of stug

52、gl e fr the i ddas of communiim, communst str I gge fr lie, eayt o - ciie frthe paly a nd t he pepe Se Iuousymprovethequaiyaditandadofpolla,IonsietiousystudyDegiapigtheoryadthrreeprsetsmportanttIoughtandthesietiiOtookondeelpmet,mIementthepalysbascprogamfrtheprmarysageofsciai, ahee to t I e core ct p

53、olti ca orietatin, maita n hg wihthecPccentalcommiteesgooda theresofsoci m wi h chie se chaatei sist I ana ly e ad solve pr obem slid, steg hei ng the paty srt andtewoltansfrmaton,pe-veace of the pary const.n,relvePatyvstoe bls crect -orl l Oltoo、 OLlok on Ie ad theworldpra“des i ddas ad be lies ito

54、 ajin, cmbi I e lofty ieas a n.praji l ictvie s, tasormi ng the o, - ord, a.iaSpariipae i n te grea pra ctie if bui dig scaim wihchaacteisis2,k- p the purooe i n concet cha ngig the sl e ofwkF - t k- p in mind ta the pur pose of iervi ng, a dhee t a isumi ng poer fr the pepe k-pimidtepepeadcaealout

55、pe ope a nd t he joys a ndsros of te mcco rig to ciy disili nemuniipa org aniain De_me nti ns tday e hel d mp e ment mpl tain ideet commiionist corr upton gui del n efetie sgtheninglestye conntucin tpic tciemant kisclconta ct tought and wok a ctual contrl che ck dijti ct Stadi ng committad te a in i

56、mpl etainit commi ionaanstcorruptonguiein Sage of pro bl i de pth ie d out ciii lcdtcalfrtecl ctfc a ind cton ad m efetieehcl poii-s of consious andiniatvef_t good of rlngmBet I Ig t heaye tke s sl cie a ve ws combe d reate t tbuiding2 .程序源代碼:#include "stdio.h"#include "conio.h"main()char a=176,b=219;printf(&qu

溫馨提示

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

評論

0/150

提交評論