


版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1.3.1:請(qǐng)參照本章例題,編寫一個(gè) C 程序,從鍵盤上輸入圓的半徑,求園的周長(zhǎng) 和以此半徑所組成的球的體積。/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h"main() float r,c,v,pi=3.14;printf("r:"); scanf("%f",&r);c=2*pi*r;v=4.0/3*pi*r*r*r;printf("c=%fn",c);printf("v=%fn",v)
2、;getch();1.3.2:編寫一個(gè) C 程序,輸入 45,21,60 三個(gè)數(shù)字,輸出其中的最大者。/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h"int max(int x,int y,int z)int m;m=x>y?x:y;return(m>z?m:z);main() int x,y,z;printf("x:"); scanf("%d",&x);printf("y:");scanf(&q
3、uot;%d",&y);printf("z:");scanf("%d",&z);printf("max=%dn",max(x,y,z);getch();2.6.1.1:觀察分析程序的結(jié)果,并與人工計(jì)算結(jié)果進(jìn)行比較。/* HELLO.C - Hello, world */#include "stdio.h"void main()char c1,c2;c1=97;c2=98;printf("%c %cn",c1,c2);printf("%d %dn",c
4、1,c2);c1=c1-('a'-'A');printf("%c %cn",c1,c2);getch();2.6.2:參照下列求圓面積與園周長(zhǎng)的程序,編寫已知圓半徑、圓柱高,求圓周長(zhǎng) 和圓柱體積的程序。/* HELLO.C - Hello, world */#include "stdio.h"#define pi 3.1415926void main() float r,h,v,len;printf(" r:"); scanf("%f",&r);printf(" h
5、:");scanf("%f",&h);len=2*pi*r; v=pi*r*r*h;printf("n v=%f,length=%f",v,len);getch();3.7.1:編寫程序,使得該程序運(yùn)行后顯示下面一首詩(shī):life is dear indeed, love is priceless too, but for freedom 's sake, I may part with the two./* HELLO.C - Hello, world */#include "stdio.h"#include
6、 "conio.h" main()printf("life is dear indeed,nlove is priceless too,nbut for freedom's sake,nI may part with the two.");getch();3.7.2:用格式控制符打印下面圖形:*/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h" main()*n*n *n*");printf(" getch()
7、;3.7.3:編寫程序,輸入一個(gè)華氏溫度(F),按下面的公式計(jì)算并輸出對(duì)應(yīng)的攝氏 溫度( C ) 。計(jì)算公式為 C=5(F-32)/9 。/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h" main() float F,C; printf("F:"); scanf("%f",&F); C=5*(F-32)/9; printf("C=%fn",C); getch();4.5.1:編寫程序,輸入一個(gè)日期,判斷該日期
8、是這一年的第幾天/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h"main() int day,month,year,sum,leap; printf("nplease input year,month,dayn"); scanf("%d,%d,%d",&year,&month,&day); switch(month)case 1:sum=0;break;case 2:sum=31;break;case 3:sum
9、=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;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;if(year%400=0|(year%4=0&&year%100!
10、=0) leap=1;elseleap=0;if(leap=1&&month>2)sum+;printf("it is the %dth dayn",sum);getch();4.5.2:編寫程序,對(duì)于輸入的三個(gè)數(shù),將他們降序輸出/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h" main() float x,y,z,temp;printf("Please input three number:n");scanf(&
11、quot;%f,%f,%f",&x,&y,&z);if (x>y)temp=x;x=y;y=temp;if (x>z)temp=x;x=z;z=temp;if (y>z)temp=y;y=z;z=temp;printf("the sequence is:%3.1f,%3.1f,%3.1fn",z,y,x);getch();4.5.4:某大型電器公司在國(guó)慶節(jié)期間推出以下促銷優(yōu)惠活動(dòng):當(dāng)天所購(gòu)商品價(jià)值 在 20000 元以上(包括 20000元)的顧客,將享受 7.5 折優(yōu)惠;當(dāng)天所購(gòu)商品價(jià) 值在 15000 元以上(包括 1
12、5000 元)的顧客,將享受 8 折優(yōu)惠;當(dāng)天所購(gòu)商品 價(jià)值在 10000元以上(包括 10000元)的顧客,將享受 8.5 折優(yōu)惠;當(dāng)天所購(gòu)商 品價(jià)值在 5000元以上(包括 5000元)的顧客,將享受 9 折優(yōu)惠;其他顧客享 受 9.5 折優(yōu)惠。編寫實(shí)現(xiàn)該優(yōu)惠活動(dòng)的程序。/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h"main()float x;float y;printf("please input a x:n");scanf("%f&qu
13、ot;,&x);if(x>=20000)y=x*0.75;else if (x>=15000)y=x*0.8;else if (x>=10000)y=x*0.85;else if (x>=5000)y=x*0.9;elsey=x*0.95;printf("%fn",y);getch();4.5.5:寫出實(shí)現(xiàn)以下函數(shù)的對(duì)應(yīng)程序,要求:輸入x,計(jì)算并輸出函數(shù)y的值(保留兩位小數(shù))。X+10 ,( x<0)Y= 20 , (x=0)30x, (x>0)/* HELLO.C - Hello, world */#include "
14、stdio.h"#include "conio.h"main()float x;float y;printf("please input a x:n");scanf("%f",&x);if(x>0)y=x*30;else if(x<0)y=x+10;elsey=20;printf("%fn",y);getch();4.5.10:輸入一個(gè) 4位正整數(shù),求出對(duì)應(yīng)位的數(shù)字并輸出, 最后將千位和十位互換, 百位和個(gè)位互換并輸出(例:輸入 1256,最后輸出 5612),其他輸入提示錯(cuò)誤。 #i
15、nclude "stdio.h"void main()int x,y,a,b,c,d;printf("please input one number:");scanf("%i",&x);if(x>=1000&&x<10000) a=x%10;printf("%dn",a); b=(x/10)%10;printf("%dn",b); c=(x/100)%10;printf("%dn",c);d=(x/1000)%10;printf("
16、;%dn",d);y=b*1000+a*100+d*10+c;printf("%dn",y);elseprintf("sorry ERROR");getch();5.5.3.2:編一程序輸出如下圖形:1121123211234321123454321/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h"main() int i,j;for(i=1;i<=6;i+) for(j=1;j<=6-i;j+)printf(&qu
17、ot; "); for(j=1;j<=i;j+) printf("%d",j); for(j=i-1;j>=1;j-)printf("%d",j);printf("n");getch();5.6.3:設(shè)計(jì)程序輸出 Fibonacci 數(shù)列的前 50 個(gè)數(shù),其開始兩個(gè)數(shù)是 1、1,從第 個(gè)數(shù)開始,每個(gè)數(shù)等于前兩個(gè)數(shù)之和。例如, 1、1、2、3、 5、 8、13、 /* HELLO.C - Hello, world */#include "stdio.h"#include "conio.
18、h" int main()long x16 = 0,1;int i;for(i=2;i<16;i+) xi = xi-1+xi-2; for(i=1;i<16;i+) printf("F%d=%dn",i,xi);getch ();5.6.7:用循環(huán)程序輸出以下圖案。*/* HELLO.C - Hello, world */#include "stdio.h"#include "conio.h"void main()int a,b,c; for(a=1;a<=4;a+) for(b=1;b<=4-a;
19、b+) printf(" ");for(c=2;c<=2*a;c+) printf("*");printf("n"); for(a=0;a<=2;a+)for(b=0;b<=a;b+) printf(" ");for(c=0;c<=4-2*a;c+)printf("*");printf("n");getch();568:用以下公式計(jì)算圓周率n的近似值。n /4=1-1/3+1/5-1/7+/* HELLO.C - Hello, world */#inc
20、lude "stdio.h"#include "conio.h"void main()double pi=0.0,i=1.0,j=1.0;for(;i<100000000;i+=2,j=-j)pi+=1/(i*j);pi=pi*4;printf("pi=%lf",pi);getch();5.6.10:猴子吃桃問(wèn)題。猴子第一天摘下若干桃子,當(dāng)即吃了一半,還不過(guò)癮,又多吃了一個(gè)。第二天將剩下的桃子吃了一半,又多吃了一個(gè)。以后每天都吃前一天剩下的一半零一個(gè)。到第十天再想吃時(shí),就只剩下一個(gè)桃子了求第一天共 摘了多少桃子。/* HELLO
21、.C - Hello, world */#include "stdio.h"#include "conio.h"main() int n=1,i;i=0 ;while(i<9)n=2*(n+1);+i;printf("%d",n);getch();6.5.1:有 8 位青年歌手參加歌曲大獎(jiǎng)賽, 有 1 0個(gè)評(píng)委對(duì)他們的演唱進(jìn)行打分, 試 編程序求各位選手的平均分(去掉一個(gè)最高分和一個(gè)最低分) 。#include "stdio.h"#include "conio.h"main() float
22、 i,n,k,s=0;float max ,min;float a10;printf ("please input 10 number:n") ; for(i=0;i<10;i+) scanf("%f",&ai); max=a0;k=0; min=a0;n=0;for(i=0;i<10;i+)if (ai>max) max=ai;k=i; for(i=0;i<10;i+)if (ai<min) min=ai;n=i; for(i=0;i<10;i+)s=s+ai;s=(s-ak-an)/8.0;printf("%0.1f",s);getch();6.6.6.2:輸入 5*5 的矩陣,編程實(shí)現(xiàn):( 1) 分別求兩對(duì)角線上的各元素之和。( 2) 求兩對(duì)角線上行、列下標(biāo)均為偶數(shù)的各元素之和 #include "stdio.h" #include "conio.h"main() int a55;int i,j,s1,s2,sum1=0; printf("
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- LED戶外屏施工方案
- 勞務(wù)分包合同年度分包
- 現(xiàn)代服務(wù)業(yè)運(yùn)營(yíng)與管理案例分析題集
- 路面鋪裝施工方案
- 工程木工承包合同
- 水生植物的施工方案
- 露天煤礦施工方案
- TCSHB 0023-2024 中型可編程控制柜設(shè)計(jì)規(guī)范
- 導(dǎo)流明渠開挖專項(xiàng)施工方案
- 地暖排管現(xiàn)場(chǎng)施工方案
- 跨國(guó)合作在醫(yī)藥研發(fā)中的應(yīng)用與挑戰(zhàn)
- 2025年皖北衛(wèi)生職業(yè)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫(kù)審定版
- 膀胱灌注課件
- 2025年足療店勞務(wù)用工合同模板
- 北京版五年級(jí)下冊(cè)數(shù)學(xué)計(jì)算題專項(xiàng)練習(xí)1000道帶答案
- 2025年黑龍江交通職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫(kù)必考題
- 2024年02月山東2024齊魯銀行德州分行社會(huì)招考筆試歷年參考題庫(kù)附帶答案詳解
- 《新中國(guó)史》課程教學(xué)大綱
- 2025年劃船健身器項(xiàng)目投資可行性研究分析報(bào)告
- 南京市江寧區(qū)2023-2024六年級(jí)數(shù)學(xué)下冊(cè)第一二單元練習(xí)及答案
- 2025-2030年中國(guó)化工園區(qū)行業(yè)發(fā)展現(xiàn)狀及投資前景分析報(bào)告
評(píng)論
0/150
提交評(píng)論