

下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、初級編程入門題123、初級編程入門題1 1、請編寫一個程序,求一個正方的周長。Program ex1;Var a,s:real;Begi nReadl n(a);S:=a*4;Writel n(s);End.2 2、請編寫一個程序,求一個長方形的周長。Program ex2;Var a,b,s:real;Begi nReadl n(a,b);S:=(a+b)*2;Writel n(s);End.3 3、請編寫一個程序,求一個三角形的周長。Program ex3;Var a,b,c,s:real;Begi nReadl n(a,b,c);順序結(jié)構(gòu)S:=a+b+c;Writel n(s);En d
2、.4 4、請編寫一個程序,從鍵盤輸入兩個整數(shù),要求求和然后輸出和。例如:輸入 1 14 4輸出 5 5Program ex4;Var a,b,s:real;Begi nReadl n(a,b);S:=a+b;Writel n(s);En d.5 5、要求從鍵盤輸入一個三位數(shù),要求百位變十位,十位變個位,個位變百位例如:輸入 123123輸出 312312Program ex5;Var x, a,b,c,d,s:real;Begi nReadl n(x);A:=x div 100;B:=x mod 100;C:=b div 10;D:=b mod 10;S:=d*100+c*10+a;Write
3、l n(s);End.6 6、輸入一個四位數(shù)要求按如下交換輸出:例如:輸入 12341234 輸出 43214321Program ex6;Var x, a,b,c,d,e,f,s:real;Begi nReadl n(x);A:=x div 1000;B:=x mod 1000;C:=b div 100;D:=b mod 100;E:=d div 10;F:=d mod 10;S:=f*1000+e*100+c*10+a;Writel n(s);End.7 7、輸入一個四位數(shù)要求輸入各位數(shù)字的和。例如:輸入 45674567輸出 2222Program ex6;秒Var x, a,b,c,d
4、,e,f,s:real;Begi nReadl n(x);iA:=x div 1000;B:=x mod1000;C:=b div100;D:=b mod100;E:=d div10;F:=d mod10;S:=f+e+c+a;Writel n(s);En d.8 8、編一程序,鍵盤輸入整數(shù) A A , B B 的值,然后打印 A A 除以 B B 的商的整數(shù)部分及余數(shù)。Program ex2;Var a,b,c,d:real;Begi nReadl n(a,b);C:=a div b;D:=a mod bWritel n(c, d);En d.9 9、輸入一個時、分、秒,把它轉(zhuǎn)換為一個秒數(shù)。
5、例如輸入 2 2 3 3 4 4 代表 2 2 小時 3 3 分鐘 4 4輸出 73847384 代表一共有 73847384 秒Program ex9;Var a,b,c,s:i nteger;Begi nReadl n(a,b,c);S:=a*3600+b*60+c;Writel n(s);En d.1010、求三角形面積:給出三角形的三個邊長為 a a, b b , c c,求三角形的面積。 提示:根據(jù)海倫公式來計算三角形的面積:a a b b c c_S S=; AreaArea S( (Sa)(a)(S b)(S)(S c)c)Program ex10;Var a,b,c,s,are
6、a:real;Begi nReadl n(a,b,c);S:=(a+b+c)2;Arer:=sqrt(s*(s-a)*(s-b)*(s-c);Writel n(s);End.1111、編一程序,從鍵盤輸入整數(shù) A A , B B 的值,然后把 A A , B B 的值交換后輸出。Program ex11;Var a,b,t:i nteger;Begi nReadl n(a,b);t:=a,a:=b;b:= t;Writel n(a,b);End.1212、 從鍵盤輸入兩個整數(shù),打印出更小的那個數(shù)。Program ex3;Var a,b:i nteger;Begi nReadl n(a,b);I
7、f ab the nwritel n(a)ElseWritel n(b);End.選擇結(jié)構(gòu)1313、 讀入三個整數(shù),從小到大輸出。Program ex13;Var a,b,c,t:i nteger;Begi nReadl n(a,b,c);If ab the n t:=a;a:=b;b:= t;If b:c the n t:=b;b:=c;c:= t;If ca the nt:=c;c:=a;a:= t;Writel n(a,b,c);End.1414、 從鍵盤輸入一個數(shù),判斷它的奇偶性,如果是奇數(shù)則輸出 yes,yes,否則輸出 nono。Program ex14;Var a:i ntege
8、r;Begi nReadl n(a);If s mod 2=1 the n Writel n( yeselse Writeln( no;End.1515、 從鍵盤讀入一個數(shù),判斷它的正負。是正數(shù),則輸出 +,是負數(shù),則輸出-Program ex15;Var a:i nteger;Begi nReadl n(a);If a0 then Writel n( +If a0 ) the nWritel n( yesEnd.Var a,b,t:i nteger;Begi nReadl n(a,b);If a50 the n a:=50*0.19+(w-50)*0.10elseWriteln(no;171
9、7、輸入兩個數(shù)a,ba,b,輸出較大數(shù)的平方值。Programex11;Else a:=w*0.15;Writel n( w,a,);End.1919、某超市為了促銷,規(guī)定:購物不足 6060 元的按原價付款,超過 6060 不足 200200 的按九折付款,超過 200200 元的,超過部分按八折付款。編一程序完成超市的自動計費的工作。Var a,b: real;Begi nReadl n(a);If a200 then b:=a*0.8Else b:=a*0.9;Writel n(a,=;b);End.(提示:A A、閏年的計算方法:年數(shù)能被 4 4 整除,并且不能 被 10100 0整除
10、;或者能被 400400 整除的整數(shù)年份。B B、利用 MODMOD 運算可以判斷一個數(shù)能否 被另一個數(shù)整除)。program day(i nput,output);var year, mon th, days: in teger;begi nread(year, mon th);Programex16;If a0 ) the nWritel n( X;x)End.2222、 編寫一個程序,功能是從鍵盤輸入三個整數(shù),打印出其中最大的一個值。Program ex22;Var a,b,c,t:i nteger;Begi n4,6,9,11(year mod 1000) or(year mod 40
11、0 =0)the ndays:=29elsedays:=28;Read ln( a,b,c);Program ex24;If ab tnent:=a;a:=b:b:= t;If bc the nt:=b;b:=c;c:= t;If cathe nt:=c;c:=a;a:= t;Writeln(a,b,c,a);En d.2323、當前小學生的成績單由以前的百分制改為優(yōu)秀、良好、合格、不合格四個等級的等級制編一程序完成分數(shù)的自動轉(zhuǎn)換工作。轉(zhuǎn)換規(guī)則如下:6060 分以下的為不合格;6060 到 6969 分更簡明)Program ex22;Var a, d:real;Begi nReadl n(a
12、);D:=a div 10;If d6 tnen writeln( buhegeIf d5thenwriteln(hegeIf d6the nwrite Inlia nghaoElse wriyeln( youxiu;En d.循環(huán)結(jié)構(gòu)分別用 repeatrepeat ,whilewhile 循環(huán)做以下習題。2424、計算 1 1 10001000 之間能同時被 3 3 和 5 5 整除的整數(shù)的和為合格;7070 到 8989 分為良好;9090 分以上的為優(yōu)秀(提示:可以利用 DIVDIV 運算來使程序Program ex26;Var x,s:i nteger;Begi nS:=0;For
13、x:=1 to 1000 doIf ( x mod 3=0 ) and (x mod5=0) the ns:=s+x;Writeln(x,s);End.2525、求所有的三位數(shù)中十位數(shù)能被個位數(shù)和百位數(shù)之和整除的數(shù)。Program ex25;Var x:i nteger;Begi nFor x:=100 toWriteln(a,b,c,a);End.2626、求水仙花數(shù)。所謂水仙花數(shù),是指一個三位數(shù) abcabc,如果滿足 a aA3+b3+bA3+c3+cA3=abc3=abc 則 abcabc 是水仙花數(shù)。999 doIf ab tnent:=a;a:=b:b:= t;If bc the
14、nt:=b;b:=c;c:= t;If cathe n t:=c;c:=a;a:= t;Var x,a,b,c,d:integer;Begi nFor x:=100 to 999 doA:=x div 100;D:=xmod100;b:=ddiv10;c:=dmod10;If (a*A*a+b*b*b+c*c*c=a*100+b*10+c)Writel n(a*100+b*10+c);En d.2727、求所有滿足條件的四位數(shù):(1)(1)這四位數(shù)是 1111 的倍數(shù);Program ex271;Var x:i nteger;Begi nFor x:=1000 to 9999 doIf x m
15、od1仁0the nWritel n(x);End.(2)(2) b+c=a+d;b+c=a+d;the nProgram ex272;Var x:i nteger;Begi nto 9999 do1000;1000;100;100;10;10;tha nProgram ex2811;Var l,s:i nteger;Begi nS:=1;For i:=1 to 33 doS:=s+i*3;Writel n(s);For x:=1000A:=xdivE:=xmodB:=edivF:=emodC:=fdivD:=fmod1Ifb+c=a+dWritel n(x);End1.2828、計算下列式子
16、的值:(1 1) 1+3+1+3+ +99+99End.Program ex2812;VarI,s:i nteger;Begi nS:=1;Fori:=1 to 99 doIfI mod 3=0the nS:=s+i*3;Writel n(s);End.(2 2)1+2+4+81+2+4+8+ +1024+10242929、 輸入一個整數(shù),計算它各位上數(shù)字的和。(注意:是任意位的整數(shù))3030、輸入一整數(shù) A A,判斷它是否質(zhì)數(shù)。(提示:若從 2 2 到 A A 的平方根的范圍內(nèi),沒有一數(shù)能整除 A A,則 A A 是質(zhì)數(shù)。)用foifoi-循環(huán)做以下習題3131、 1 1 + 3+5+3+5
17、+ .+.+.99=?.99=?3232、 1+1/2+1/3+1/4+1+1/2+1/3+1/4+1/100=?1/100=?3333、 1*2+2*3+3*4+1*2+2*3+3*4+n*(n+n*(n+1)=?+1)=?3434、 1+1/2!+1/3!+1+1/2!+1/3!+.1/n!=?.1/n!=?3535、求水仙花數(shù)。所謂水仙花數(shù),是指一個三位數(shù)abcabc,如果滿足 a aA3+b3+bA3+c3+cA3=abc3=abc則 abcabc 是水仙花數(shù)。Program ex26;Var x,a,b,c,d:integer;Begi nFor x:=100 to 999 doA:=x div 100;D:=xmod100;b:=ddi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 企業(yè)發(fā)展戰(zhàn)略制定與規(guī)劃實務
- 農(nóng)業(yè)灌溉水窖管理辦法
- 效率提升:關鍵指標勝任模型平衡記分卡
- 新質(zhì)生產(chǎn)力推動無償獻血事業(yè)的高質(zhì)量發(fā)展
- 化妝品市場未來發(fā)展趨勢預測與規(guī)劃
- 供銷職工餐廳管理辦法
- 醫(yī)療資質(zhì)銷售管理辦法
- 土壤污染治理技術(shù)
- 古詩詞賞析教學方案
- 河南酒店采購管理辦法
- 低碳生活綠色環(huán)保演示文稿
- 過盈配合壓入力計算公式
- 第八章-材料工程-倫理問題-全
- 婚前協(xié)議(保護女方利益)
- 奉賢區(qū)教育系統(tǒng)師德師風建設學習測試附有答案
- 扶貧農(nóng)產(chǎn)品購銷合同協(xié)議(農(nóng)產(chǎn)品購銷合同模板)
- 汽車維修高級工考試試題及參考答案
- GB/T 5782-2016六角頭螺栓
- GB/T 23445-2009聚合物水泥防水涂料
- GB/T 13451.2-1992著色顏料相對著色力和白色顏料相對散射力的測定光度計法
- GB/T 11264-2012熱軋輕軌
評論
0/150
提交評論