版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、實用標(biāo)準(zhǔn)文案C語言程序設(shè)計張淑華、朱麗莉主編課后習(xí)題解答僅供參考、選擇題1 . B6. C二、填空題1 . .obj 2函數(shù)./* */.#include<stdio.h> inta,b; a,b三、簡做題略、選擇題1 .B2.B3.A4.D5.A6.C7.C8.A9.C10.B11.,A12.A13.C14.A15.C二、填空題1.變量5. 16.存儲數(shù)據(jù)的單元.非0、.38(1)a>=0 (2)0. 4 , 710. -6 17777211.9.912三、寫出以下程序的運行結(jié)果1. 0, 0, 52. 185. d4,c512四、編程題1 . #include <s
2、tdio.h>#define PI 3.1415926void main()float r,s; printf( scanf( s=PI*r*r; printf(“Please input circinal radiin "f,&r);“r=%.2f,s=%.2fn ,r,s););2.#include <stdio.h>void main()精彩文檔實用標(biāo)準(zhǔn)文案 char c1,c2;printf( " Please input a majusculen ");scanf("%C ,&c1);c2=c1>'
3、; A &&c1<' Z' ?c1+32:c1;printf(" cn,c2);3. #include <stdio.h>void main() int a=0,b;scanf("%C ,&b);b=b&a;printf(" b=%dn ,b);習(xí)題三一、選擇題1. C 2, C 3.A 4. C 5. D6 .原題第2行應(yīng)為c=(c-=a-5),(a=b,b+3); 答案為B否那么輸出結(jié)果為5,0,57 . D 8. C 9. A 10. B二、填空題1 . -50 300、a=-50,b=300
4、a=-50b=3002. 10 20 30、10,20,30、a=10,b=20,c=303. 15、 0、 0三、寫出以下程序的運行結(jié)果1 . a=789.654321,a= 789.65,a= 789.65432100,a=789.6543212. b=15,b=17,b=f35.在TC環(huán)境下為216,125.c=1,x=0,y=0,z=1420,20在VC環(huán)境下為216,1809,4,12,126 . a=A,b=d,c=F 8. x=4.500000,y=4,x+y=8.500000四、編程題1 . #include <stdio.h>void main()printf(*
5、n");printf(" HAPPY NEW YEAR! n");2.printf("*n");精彩文檔實用標(biāo)準(zhǔn)文案(1) #include <stdio.h> void main() int a=5,b=8,c=10,m,max;m= a>b?a:b;max=c>m?c:m;printf("max=%dn' ,max);(2)#include <stdio.h>void main() int a,b,c,m,max;scanf("%d,%d,%d",&a,&am
6、p;b,&c);max=a>b?a:(b>c?b:c);printf("max=%drT ,max);、選擇題1 . D2.D3.C46. A7.C8.C9、填空題1. 6、5、52. (a%3=0|a%7=0)3 a>b (2) a=c; a,b,c三、寫出以下程序的運行結(jié)果1. 42. 643. a=7,b=446四、編程題1.另見填空題3#include <stdio.h>void main() float a,b,c,t;scanf("%f,%f,%f",&a,&b,&c);if (a>b
7、) t=a;a=b;b=t;if (a>c)t=a;a=c;c=t;if (b>c)t=b;b=c;c=t;printf( ".2f,%.2f,%.2fn",a,b,c);4. 46465*#2. #include <stdio.h>void main()精彩文檔實用標(biāo)準(zhǔn)文案 int a,b;scanf("%d,%d",&a,&b);if(a%b=0)printf("%d is divisible by %dn ,a,b);elseprintf("%d is not divisible by %
8、dn ,a,b);3. (1) #include <stdio.h>void main() int x,y;scanf("%d ,&x);if (x>-5&&x<0)y=x;printf("y=%dn",y);else if (x=0)y=x-1;printf("y=%dn",y);else if(x>0&&x<10)y=x+1;printf("y=%dn",y);elseprintf("Data out of rangen");
9、(2) #include <stdio.h>void main() int x,y;scanf("%d',&x);switch(x) case -1:case -2:case -3:case -4:y=x; printf("y=%dn",y);break;case 0:y=x-1; printf("y=%dn",y);break;case 1:case 2:case 3:case 4:case 5:case 6:case 7:case 8:case 9:y=x+1; printf("y=%dn",
10、y);break;default: printf("Data out of rangen");精彩文檔實用標(biāo)準(zhǔn)文案4. #include <stdio.h>void main()(long num;int indiv,ten,hundred,thousand,tenthousand,place;/*分別代表個位、十位、百位、千位、萬位和位數(shù) */printf( "Please Input a integer(099999):");scanf( "%ld ,&num);if (num>9999)place=5;else
11、if (num>999)place=4;else if (num>99)place=3;else if (num>9)place=2;elseplace=1;printf("place=%dn " ,place);printf("For each digit: ");tenthousand=num/10000;thousand=(int)(num-tenthousand*10000)/1000;hundred=(int)(num-tenthousand*10000-thousand*1000)/100;ten=(int)(num-ten
12、thousand*10000-thousand*1000-hundred*100)/10;indiv=(int)(num-tenthousand*10000-thousand*1000-hundred*100-ten*10);switch(place)(case 1:printf("%d ,indiv);break;case 2:printf("%d,%d ,ten,indiv);break;case 3:printf("%d,%d,%d ,hundred,ten,indiv);break;case 4:printf("%d,%d,%d,%d ,thou
13、sand,hundred,ten,indiv);break;case5:printf( " %d,%d,%d,%d,%d ,tenthousand,thousand,hundred,ten,indiv);)習(xí)題五D4. B5. CB9. B10. B一、選擇題1. D2, C36. B7, C8二、填空題1. (1) x>=0 或!(x<0)(2) x<amin精彩文檔實用標(biāo)準(zhǔn)文案)j%3 或 j%3!=02. (1) i<10 或 i<=9(23. (1) pi (2) fabs(t) (3)4三、寫出以下程序的運行結(jié)果1 . 16. 45.a=2,b
14、=853423四、編程題1. #include <stdio.h>void main() int i,j,k;輸出上面4彳T*號*/for (i=1;i<=4;i+) /* for (j=1;j<=5-i;j+)printf(");/* 輸出*號前面白空格*/for (k=1;k<=2*i-1;k+)2.printf( printf( );/* 輸出*號*/“n");/*輸出完一行*號后換行*/#include "stdio.h"void main() int num,n1,n2,p=1;scanf("%d&quo
15、t;,&num);while (num) n1=num/10;n2=num%10;p*=n2;num=n1;)printf("num=%d,p=%dn",num,p);3.)#include "stdio.h"void main() int i;float s1,s2,s3,s4,s5,sum,avg;for(i=1;i<=6;i+) printf("Please enter a five subjects scoren");scanf("%f,%f,%f,%f,%f",&s1,&s2
16、,&s3,&s4,&s5);sum=0;sum+=s1+s2+s3+s4+s5;avg=sum/5;精彩文檔實用標(biāo)準(zhǔn)文案printf("%d individuals,the average score is %.2fn",i,avg);習(xí)題六一、選擇題1. D2. C36. A7. C8二、填空題.3. (1) j=9 (2) j>=04. (1) 0 (2).(1) i<3 (2)aii1 .地址常量 2 .非036 5. (1) gets(temp); (2) strcpy(temp,str); 67. (1) &ai(2)
17、i%4=0(3)printf("n:");8. (1) si>=48 && si<=57或 si>='0' && si<='9' (2) dj=0;或 dj='0'三、寫出以下程序的運行結(jié)果1. 137152. s=153. 584. 115.7 06. how7. max=9,row=1,col=0 8. 6,4,3,2,are you? I am fine四、編程題1 . #include <stdio.h>#define N 10 void main()
18、 int a32,x,k,r,i;printf( " Please input an integer:");k=-1;do r=x%2;a+k=r;x/=2;)while(x>=1);for(i=k;i>=0;i-)printf( "1d ,ai);printf( "n );)2. #include <stdio.h>#define N 10 void main() int aN+1=10,20,30,40,50,60,70,80,90,100;int t1,t2,num,i,j;精彩文檔實用標(biāo)準(zhǔn)文案printf( "a
19、rray a:n ");for (i=0;i<N;i+)printf( "%d ,ai);printf("n );printf("Insert data:");scanf( "%d' ,&num);if (num>aN-1) aN=num;else for (i=0;i<N;i+) if (ai>num) t1=ai;ai=num;for (j=i+1;j<N+1;j+) t2=aj;aj=t1;t1=t2; break;printf("Current array a:n&quo
20、t;);for (i=0;i<N+1;i+)printf( "%5dn",ai);3. #include <stdio.h>#define N 6void main() int i,j,aNN;for (i=1;i<N;i+) aii=1;ai1=1;for (i=3;i<N;i+)for (j=2;j<i-1;j+)aij=ai-1j-1+ai-1j;for (i=1;i<N;i+) for (j=1;j<=i;j+)printf( "5d ,aij); printf( " n " );4. #
21、include "stdio.h" void main() char s80,t80,d;int i,j;printf("Please enter a string:n");gets(s);精彩文檔實用標(biāo)準(zhǔn)文案printf("delete?n");d=getchar();for(i=j=0;si!='0'i+)if(si!=d)tj=si;j+; tj='0'printf("%sn",t);5. #include "stdio.h"#define N 8 void
22、 main() int sN3,i,j,k,m,t1;float aN,sum,t2;for(i=0;i<N;i+) printf("Please enter the %d-th three subjects scoren",i); sum=0;for(j=0;j<3;j+) scanf("%d",&sij); sum+=sij;ai=sum/3;for(i=0;i<N-1;i+) k=i;for(j=i+1;j<N;j+) if(ak<aj) k=j; if(k!=i) for(m=0;m<3;m+) t1=
23、sim;sim=skm;skm=t1; /*交換整行的值 */t2=ai;ai=ak;ak=t2;for(i=0;i<N;i+) printf("%d-th ",i);for(j=0;j<N;j+)printf("%d ",sij);printf("%.2fn",ai); 習(xí)題七一、選擇題1. C 2.A 3. B 4. B 5.A精彩文檔實用標(biāo)準(zhǔn)文案6. D 7, C 8. D 9. C 10. C二、填空題1 . struct STRU t20;2. x.x、x.y、x.z.y、x.z.z 3. 4,8三、寫出以下程序
24、的運行結(jié)果1 . 62. 03. 4E5S 4. 215. Zhao,m,85,90四、編程題2 . #include "stdio.h"#define N 45 struct student char name20;char sex7;int age;int score;stdN;void main() int i,max=0,rowi;for(i=0;i<N;i+) printf("Please enter the data of the %d-th student:n",i);printf("name:");scanf(&
25、quot;%s",);printf("sex:");scanf("%s",stdi.sex);printf("age:");scanf("%d",&stdi.age);printf("score:");scanf("%d",&stdi.score);if(max<stdi.score) max=stdi.score; rowi=i;printf("name:%s ",);printf
26、("sex:%s ",stdrowi.sex);printf("age:%d ",stdrowi.age);printf("score:%dn",stdrowi.score);3 . #include "stdio.h"#define N 5 struct student char name20;char sex7;精彩文檔實用標(biāo)準(zhǔn)文案int score;stdN;void main() int i,ml=0,fml=0;float sum=0,avg;for(i=0;i<N;i+) printf("
27、;Please enter the data of the %d-th student:n",i);printf("name:");scanf("%s",);printf("sex:");scanf("%s",stdi.sex);if(stdi.sex0='m'|stdi.sex0='M')ml+=1;elsefml+=1;printf("score:");scanf("%d",&stdi.score);su
28、m+=stdi.score;avg=sum/N;printf("The number of male students:%dn",ml);printf("The number of female students are:%dn",fml);printf("The average scores are:%.2fn",avg);一、選擇題1. A2. C3. D6. A7. D二、填空題1 . (1) high=mid-1 (2) low=mid+1 2 s3. (1) max=xij (2) max三、寫出以下程序的運行結(jié)果1 . 6
29、252. Qian,p,95,923. 24. A 5. C(1) int m (2)m%i=0 (3) return4. 125. h=8四、編程題1. . #include "stdio.h void main() int prime(int);int x;精彩文檔實用標(biāo)準(zhǔn)文案printf("nPlease input an integer:"); scanf("%d",&x);if(prime(x)printf("n%d is prime.n",x);elseprintf("n%d is not pr
30、ime.n",x);int prime(int n) int flag=1,i;for(i=2;i<=n-1 && flag=1;i+) if(n%i=0) flag=0;return(flag);2. #include "stdio.h"void delask(char a口) int i,j;char b80;for(i=j=0;ai!='0'i+)if(ai!='*') while(ai!='0')bj=ai;j+;i+; break; bj='0'for(i=0;bi!=
31、'0'i+)ai=bi;ai='0'void main() char s80;printf("Please enter a string:n");scanf("%s",s);delask(s);printf("%sn",s);3. #include "stdio.h"struct date int day;int month;int year;精彩文檔實用標(biāo)準(zhǔn)文案);int days(struct date dt) int y,m,d,ds12=31,28,31,30,31,30,3
32、1,31,30,31,30,31,i,s=0;y=dt.year;m=dt.month;d=dt.day;if(y%4=0 && y%100!=0|y%400=0)ds1=29;/*計算每月的天數(shù)是本年第幾天*/switch(m) case 1:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 2:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 3:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 4:for(i=0;i<m-1;i+)s+=dsi;s+=d;br
33、eak;case 5:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 6:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 7:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 8:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 9:for(i=0;i<m-1;i+)s+=dsi;精彩文檔實用標(biāo)準(zhǔn)文案s+=d;break;case 10:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;case 11:for(i=0
34、;i<m-1;i+)s+=dsi;s+=d;break;case 12:for(i=0;i<m-1;i+)s+=dsi;s+=d;break;return (s);void main() struct date ymd;int dys;printf("Input year month and dayn");scanf("%d,%d,%d",&ymd.year,&ymd.month,&ymd.day);dys=days(ymd);printf("Today is the first %d days in the
35、 middle of this year.n",dys); 習(xí)題九一、選擇題1. A 2, D 3.A 4. D 5. B 6.A二、寫出以下程序的運行結(jié)果1 . 102. 911113. *4. 125. 86. 111213三、編程題1 . #include "stdio.h"#define N 10float fmax=0,fmin=0;float average(float fscore,int n) int i;float faver,fsum=fscore0;精彩文檔實用標(biāo)準(zhǔn)文案fmax=fmin=fscore0;for(i=1;i<n;i+)(
36、if(fscorei>fmax)fmax=fscorei;else if(fscorei<fmin) fmin=fscorei;fsum+=fscorei;)faver=fsum/n;return (faver);)void main() float fave,fnumbN;int i;for(i=0;i<N;i+)scanf("%f",&fnumbi);fave=average(fnumb,N);printf("max=%.2f min=%.2f average=%.2fn",fmax,fmin, fave);)2 .此題有誤
37、,用宏定義較難實現(xiàn).以下程序僅供參考#include "stdio.h"void main() char strg30="C Language Program",c;int i=0;while(c=strgi)!='0') i+;if(c>='a' && c<='z')c=c-32;elseif(c>='A' && c<='Z')c=c+32;printf("%c",c);)printf("
38、n");)3 . #include "stdio.h"#include "math.h"#define S(a,b,c) (a+b+c)/2)#define AREA(a,b,c) sqrt(S(a,b,c)*(S(ahc)-a)*(S(a,b,c)-b)*(S(a,b,c)-c) void main() float a,b,c;printf("Please input a,b,c:");scanf("%f,%f,%f",&a,&b,&c);精彩文檔實用標(biāo)準(zhǔn)文案if (a+b>
39、;c && a+c>b && b+c>a)printf("%.2fn",AREA(a,b,c); elseprintf("It is not a triangle!n");習(xí)題十1 .B2.D3.D46.A7.A8.C911,A12.B13.C14、選擇題D5.CD10.AA15.C104.8二、寫出以下程序的運行結(jié)果1. 212.034893438. 4 4 4 45 6 7 8 9 105. CBADGFE 6. 30,307. The data:i=5 c=B三、編程題1 . #include <s
40、tdio.h>#include <string.h> void fun(char *s,int *a,int *b) while(*s!='0') if(*s>=65 && *s<=90)*a+=1; /*可用(*a)+; */if(*s>=97 && *s<=122)*b+=1; /*可用(*b)+; */s+;void main() char s100;int upper=0,lower=0;printf("請輸入一串字符:n");gets(s);fun(s,&upper,
41、&lower);printf("upper=%d,lower=%dn",upper,lower);2. #include <stdio.h>void fun(int *p1,int *p2) int p;p=*p1;*p1=*p2;精彩文檔實用標(biāo)準(zhǔn)文案*p2=p;)void main() int a,b,*p11,*p22;scanf("%d,%d",&a,&b); p11=&a;p22=&b;if(a<b) fun(p11,p22); printf("%d,%dn",a,b);)一、選擇題1. B26. C7.D3. B4.C8. A9C5D10this_is_a_test二、寫出以下程序的運行結(jié)果1 . 1,2,3,0,0,123,0,0,10 20.010000三、編程題1 . #include "stdio.h"#include "stdlib.h"void main() FILE *fp;char ch;if
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024能源環(huán)境監(jiān)測與治理服務(wù)合同范本3篇
- 2024簡易版貨運服務(wù)協(xié)議版B版
- 2024版欄桿購銷合同范本
- 2025年度XX教育培訓(xùn)機構(gòu)教學(xué)質(zhì)量不可撤銷擔(dān)保協(xié)議3篇
- 2024甲午年建筑工程砌墻分包合同
- 2024行政處罰權(quán)委托及協(xié)助執(zhí)法合作協(xié)議3篇
- 2024茶樓內(nèi)部裝飾設(shè)計合同
- 2024年適用:景點門票預(yù)訂合同
- 2025年度城市地下綜合管廊10kv配電設(shè)施建設(shè)合作協(xié)議3篇
- 2024藥材采購合同范文:中藥材市場壟斷采購合同3篇
- 信息學(xué)奧賽-計算機基礎(chǔ)知識(完整版)資料
- 數(shù)字信號處理(課件)
- 出院小結(jié)模板
- HITACHI (日立)存儲操作說明書
- 公路自然災(zāi)害防治對策課件
- (新版教材)蘇教版二年級下冊科學(xué)全冊教案(教學(xué)設(shè)計)
- 61850基礎(chǔ)技術(shù)介紹0001
- 電鏡基本知識培訓(xùn)
- 耳鳴中醫(yī)臨床路徑
- 圍堰高噴防滲墻工程監(jiān)理實施細(xì)則
- (精心整理)系動詞練習(xí)題
評論
0/150
提交評論