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

下載本文檔

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

文檔簡(jiǎn)介

1、1.3.1: 請(qǐng)參照本章例題,編寫(xiě)一個(gè)C程序,從鍵盤(pán)上輸入圓的半徑,求園的周長(zhǎng)和以此半徑所組成的球的體積。/*HELLO.C-Hello,world*/#include"stdio.h"#include"conio.h"main()floatr,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、.2: 編寫(xiě)一個(gè)C程序,輸入45,21,60三個(gè)數(shù)字,輸出其中的最大者。/*HELLO.C-Hello,world*/#include"stdio.h"#include"conio.h"intmax(intx,inty,intz)intm;m=x>y?x:y;return(m>z?m:z);main()intx,y,z;printf("x:");scanf("%d",&x);printf("y:");scanf("%d",&y);printf(&q

3、uot;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"voidmain()charc1,c2;c1=97;c2=98;printf("%c%cn",c1,c2);printf("%d%dn",c1,c2);c1=c1-('a'-'A');pr

4、intf("%c%cn",c1,c2);getch();2.6.2:參照下列求圓面積與園周長(zhǎng)的程序,編寫(xiě)已知圓半徑、圓柱高,求圓周長(zhǎng)和圓柱體積的程序。/*HELLO.C-Hello,world*/#include"stdio.h"#definepi3.1415926voidmain()floatr,h,v,len;printf("r:");scanf("%f",&r);printf("h:");scanf("%f",&h);len=2*pi*r;v=pi*r*

5、r*h;printf("nv=%f,length=%f",v,len);getch();3.7.1: 編寫(xiě)程序,使得該程序運(yùn)行后顯示下面一首詩(shī):lifeisdearindeed,loveispricelesstoo,butforfreedomssake,Imaypartwiththetwo./*HELLO.C-Hello,world*/#include"stdio.h"#include"conio.h"main()printf("lifeisdearindeed,nloveispricelesstoo,nbutforfree

6、dom'ssake,nImaypartwiththetwo.");getch();3.7.2: 用格式控制符打印下面圖形:*/*HELLO.C-Hello,world*/#include"stdio.h"#include"conio.h"main()printf("*n*n *n*");getch();3.7.3: 編寫(xiě)程序,輸入一個(gè)華氏溫度(F),按下面的公式計(jì)算并輸出對(duì)應(yīng)的攝氏溫度(C)。計(jì)算公式為C=5(F-32)/9。/*HELLO.C-Hello,world*/#include"stdio.h&q

7、uot;#include"conio.hmain()floatF,C;printf("F:");scanf("%f",&F);C=5*(F-32)/9;printf("C=%fn",C);getch();4.5.1: 編寫(xiě)程序,輸入一個(gè)日期,判斷該日期是這一年的第幾天。/*HELLO.C-Hello,world*/#include"stdio.h"#include"conio.h"main()intday,month,year,sum,leap;printf("npl

8、easeinputyear,month,dayn");scanf("%d,%d,%d",&year,&month,&day);switch(month)case1:sum=0;break;case2:sum=31;break;case3:sum=59;break;case4:sum=90;break;case5:sum=120;break;case6:sum=151;break;case7:sum=181;break;case8:sum=212;break;case9:sum=243;break;case10:sum=273;break;c

9、ase11:sum=304;break;case12:sum=334;break;default:printf("dataerror");break;sum=sum+day;if(year%400=0|(year%4=0&&year%100!=0)leap=1;elseleap=0;if(leap=1&&month>2)sum+;printf("itisthe%dthdayn",sum);getch();4.5.2: 編寫(xiě)程序,對(duì)于輸入的三個(gè)數(shù),將他們降序輸出。/*HELLO.C-Hello,world*/#incl

10、ude"stdio.h"#include"conio.h"main()floatx,y,z,temp;printf("Pleaseinputthreenumber:n");scanf("%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("thesequenceis:%3.1f,%3.1f,%3.1fn"

11、,z,y,x);getch();4.5.4: 某大型電器公司在國(guó)慶節(jié)期間推出以下促銷(xiāo)優(yōu)惠活動(dòng):當(dāng)天所購(gòu)商品價(jià)值在20000元以上(包括20000元)的顧客,將享受7.5折優(yōu)惠;當(dāng)天所購(gòu)商品價(jià)值在15000元以上(包括15000元)的顧客,將享受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)惠。編寫(xiě)實(shí)現(xiàn)該優(yōu)惠活動(dòng)的程序。/*HELLO.C-Hello,world*/#include"stdio.h"#include"conio

12、.h"main()floatx;floaty;printf("pleaseinputax:n");scanf("%f",&x);if(x>=20000)y=x*0.75;elseif(x>=15000)y=x*0.8;elseif(x>=10000)y=x*0.85;elseif(x>=5000)y=x*0.9;elsey=x*0.95;printf("%fn",y);getch();4.5.5: 寫(xiě)出實(shí)現(xiàn)以下函數(shù)的對(duì)應(yīng)程序,要求:輸入x,計(jì)算并輸出函數(shù)y的值(保留兩位小數(shù))。X+10,(x&

13、lt;0)Y=20,(x=0)30x,(x>0)/*HELLO.C-Hello,world*/#include"stdio.h"#include"conio.h"main()floatx;floaty;printf("pleaseinputax:n");scanf("%f",&x);if(x>0)y=x*30;elseif(x<0)y=x+10;elsey=20;printf("%fn",y);getch();4.5.10:輸入一個(gè)4位正整數(shù),求出對(duì)應(yīng)位的數(shù)字并輸出,最

14、后將千位和十位互換,百位和個(gè)位互換并輸出(例:輸入1256,最后輸出5612),其他輸入提示錯(cuò)誤。#include"stdio.h"voidmain()intx,y,a,b,c,d;printf("pleaseinputonenumber:");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(&qu

15、ot;%dn",c);d=(x/1000)%10;printf("%dn",d);y=b*1000+a*100+d*10+c;printf("%dn",y);elseprintf("sorryERROR");getch();5.5.3.2:編一程序輸出如下圖形:112112321123432112345432112345654321/*HELLO.C-Hello,world*/#include"stdio.h"#include"conio.h"main()inti,j;for(i=1;

16、i<=6;i+)for(j=1;j<=6-i;j+)printf("");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ù),其開(kāi)始兩個(gè)數(shù)是1、1,從第三個(gè)數(shù)開(kāi)始,每個(gè)數(shù)等于前兩個(gè)數(shù)之和。例如,/* HELLO.C - Hello, world */1、 1、 2、 3、 5、 8、 13、#include"

17、stdio.h"#include"conio.hintmain()longx16=0,1;inti;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"voidmain()inta,b,c;for(a=1;a<=4;a+)for(b=1;b<

18、=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

19、"stdio.h"#include"conio.h"voidmain()doublepi=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.C-Hello,

20、world*/#include"stdio.h"#include"conio.h"main()5.6.11: intn=1,i;i=0;while(i<9)n=2*(n+1);+i;printf("%d",n);getch();6.5.1:有8位青年歌手參加歌曲大獎(jiǎng)賽,有10個(gè)評(píng)委對(duì)他們的演唱進(jìn)行打分,試編程序求各位選手的平均分(去掉一個(gè)最高分和一個(gè)最低分)。#include"stdio.h"#include"conio.h"main()floati,n,k,s=0;floatmax,mi

21、n;floata10;printf("pleaseinput10number: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ì)角線(xiàn)上的各元素之和。( 2) 求兩對(duì)角線(xiàn)上行、列下標(biāo)均為偶數(shù)的各元素之和。#include"stdio.h"#include"conio.h"main()inta55;inti,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)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論