C語言實(shí)訓(xùn)題1-6章_第1頁
C語言實(shí)訓(xùn)題1-6章_第2頁
C語言實(shí)訓(xùn)題1-6章_第3頁
C語言實(shí)訓(xùn)題1-6章_第4頁
C語言實(shí)訓(xùn)題1-6章_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1.3.1:請參照本章例題,編寫一個C程序,從鍵盤上輸入圓的半徑,求園的周長和以此半徑所組成的球的體積。/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() 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);getch();1.3.2:編寫一個C程序,輸入45,21,60三個數(shù)字,輸出其中的最大者。/* HELLO.C - Hello, world */#include stdio.h#include conio.hint max(int x,int y,int z)int m; m=xy?x:y; return(mz?m:z);main() int x,y,z;printf(x:);scanf(%d,&x);printf(y:);scanf(%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.hvoid main() char c1,c2; c1=97;c2=98; printf(%c %cn,c1,c2); printf(%d %dn,c1,c2); c1=c1-(a-A); printf(%c %cn,c1,c2); getch();2.6.2:參照下列求圓面積與園周長的程序,編寫已知圓半徑、圓柱高,求圓周長和圓柱體積的程序。/* HELLO.C - Hello, world */#include stdio.h#define pi 3.1415926void main() float r,h,v,len; printf( r:); scanf(%f,&r); printf( h:); 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)行后顯示下面一首詩:life is dear indeed,love is priceless too,but for freedoms sake,I may part with the two./* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() printf(life is dear indeed,nlove is priceless too,nbut for freedoms sake,nI may part with the two.); getch();3.7.2:用格式控制符打印下面圖形: * * */* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() printf( *n *n *n*); getch();3.7.3:編寫程序,輸入一個華氏溫度(F),按下面的公式計(jì)算并輸出對應(yīng)的攝氏溫度(C)。計(jì)算公式為C=5(F-32)/9。/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() float F,C; printf(F:); scanf(%f,&F); C=5*(F-32)/9; printf(C=%fn,C); getch();4.5.1:編寫程序,輸入一個日期,判斷該日期是這一年的第幾天。/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() 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=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!=0) leap=1; else leap=0; if(leap=1&month2) sum+; printf(it is the %dth dayn,sum); getch();4.5.2:編寫程序,對于輸入的三個數(shù),將他們降序輸出。/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() float x,y,z,temp; printf(Please input three number:n); scanf(%f,%f,%f,&x,&y,&z); if (xy) temp=x; x=y; y=temp; if (xz) temp=x; x=z; z=temp; if (yz) temp=y; y=z; z=temp; printf(the sequence is:%3.1f,%3.1f,%3.1fn,z,y,x); getch();4.5.4:某大型電器公司在國慶節(jié)期間推出以下促銷優(yōu)惠活動:當(dāng)天所購商品價(jià)值在20000元以上(包括20000元)的顧客,將享受7.5折優(yōu)惠;當(dāng)天所購商品價(jià)值在15000元以上(包括15000元)的顧客,將享受8折優(yōu)惠;當(dāng)天所購商品價(jià)值在10000元以上(包括10000元)的顧客,將享受8.5折優(yōu)惠;當(dāng)天所購商品價(jià)值在5000元以上(包括5000元)的顧客,將享受9折優(yōu)惠;其他顧客享受9.5折優(yōu)惠。編寫實(shí)現(xiàn)該優(yōu)惠活動的程序。/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() float x; float y; printf(please input a x:n); scanf(%f,&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; else y=x*0.95; printf(%fn,y); getch(); 4.5.5:寫出實(shí)現(xiàn)以下函數(shù)的對應(yīng)程序,要求:輸入x,計(jì)算并輸出函數(shù)y的值(保留兩位小數(shù))。 X+10,(x0)/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() float x; float y; printf(please input a x:n); scanf(%f,&x); if(x0) y=x*30; else if(x=1000&x10000) 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(%dn,d); y=b*1000+a*100+d*10+c;printf(%dn,y); else printf(sorry ERROR); getch();5.5.3.2:編一程序輸出如下圖形: 1121 12321 1234321 12345432112345654321/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() int i,j; for(i=1;i=6;i+) for(j=1;j=6-i;j+) printf( ); for(j=1;j=1;j-) printf(%d,j); printf(n); getch();5.6.3:設(shè)計(jì)程序輸出Fibonacci數(shù)列的前50個數(shù),其開始兩個數(shù)是1、1,從第三個數(shù)開始,每個數(shù)等于前兩個數(shù)之和。例如,1、1、2、3、5、8、13、。/* HELLO.C - Hello, world */#include stdio.h#include conio.hint main()long x16 = 0,1;int i;for(i=2;i16;i+) xi = xi-1+xi-2;for(i=1;i16;i+)printf(F%d=%dn,i,xi);getch ();5.6.7:用循環(huán)程序輸出以下圖案。 * * * * * */* HELLO.C - Hello, world */#include stdio.h#include conio.hvoid main()int a,b,c;for(a=1;a=4;a+)for(b=1;b=4-a;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();5.6.8:用以下公式計(jì)算圓周率的近似值。/4=1-1/3+1/5-1/7+/* HELLO.C - Hello, world */#include stdio.h#include conio.hvoid main()double pi=0.0,i=1.0,j=1.0;for(;i100000000;i+=2,j=-j)pi+=1/(i*j);pi=pi*4;printf(pi=%lf,pi);getch();5.6.10:猴子吃桃問題。猴子第一天摘下若干桃子,當(dāng)即吃了一半,還不過癮,又多吃了一個。第二天將剩下的桃子吃了一半,又多吃了一個。以后每天都吃前一天剩下的一半零一個。到第十天再想吃時(shí),就只剩下一個桃子了求第一天共摘了多少桃子。/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() int n=1,i; i=0 ; while(i9) n=2*(n+1);+i; printf(%d,n); getch();6.5.1:有8位青年歌手參加歌曲大獎賽,有10個評委對他們的演唱進(jìn)行打分,試編程序求各位選手的平均分(去掉一個最高分和一個最低分)。#include stdio.h#include conio.hmain() float i,n,k,s=0; float max ,min; float a10; printf (please input 10 number:n) ; for(i=0;i10;i+) scanf(%f,&ai); max=a0;k=0; min=a0;n=0; for(i=0;imax) max=ai;k=i; for(i=0;i10;i+) if (aimin) min=ai;n=i; for(i=0;i10;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) 分別求兩對角線上的各元素之和。(2) 求兩對角線上行、列下標(biāo)均為偶數(shù)的各元素之和。#include stdio.h#include conio.hmain() int a55; int i,j,s1,s2,sum1=0; printf(1):n); printf(please input 25 numbers:n); for(i=0;i5;i+) for(j=0;j5;j+) scanf(%d,&aij); printf(n); s1=0,s2=0; for(i=0;i5;i+) for(j=0;j5;j+) if(i=j) s1=s1+aij; for(i=0;i=0;j-) if(i+j=4)s2=s2+aij; printf(s1=%d,s2=%d,s1,s2); printf(n); printf(2):n); for(

溫馨提示

  • 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)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論