版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第1章習(xí)題參照答案(略)判斷題1
2
3
4
5√
×
√
×
√填空題1)main2)函數(shù)的首部、函數(shù)體3){、}4)main、main5)語(yǔ)句、分號(hào)(;)選擇題1
2
3
4
5C
C
C
A
B選擇題(1)#include<>main(){inta,b,s;floatt;printf("EnterA,B=?\n");scanf("%d%d",&a,&b);s=a+b;t=a*b;printf("s=%d,t=%f\n",s,t);}2)#include<>main(){printf("=================\n");printf("Hello!\n");printf("Howdoyoudo\n");printf("=================\n");}3)#include<>main(){intr,h;floatv;printf("EnterR,H=?\n");scanf("%d%d",&r,&h);v=*r*r*h;printf("v=%f\n",v);}第2章習(xí)題參照答案一.(略)二.填空題b(1)acbed2ab2)3)164)105)16、16、116)4、10、67)18、3、38)sin(65*180)+2*(+exp(y))/(x-y)9)25、2510)2711)412)0三、選擇題1
2
3
4
5
6
7
8
9
1011
12D
D
C
B
D
A
D
B
C
D
A
B四、編程題1.#include<>main(){intx,a,b,c;printf("Enteraintgernumberx=?\n");scanf("%d",&x);a=x/100;b=x%100/10;c=x%10;printf("%d%d%d\n",a,b,c);}2.#include<>main(){unsigneda,b,r1,r2,r3;scanf("%u%u",&a,&b);r1=a&b;r2=a|b;r3=a^b;printf("r1=%u,r2=%u,r3=%u\n",r1,r2,r3);getch();}3.#include<>main(){floata,b,h,s;scanf("%f%f?%f",&a,&b,&h);s=(a+b)*h/2;printf("s=%f\n",s);}第3章習(xí)題參照答案一、判斷題1
2
3
4
5
6×
×
×
√
√
×填空題語(yǔ)句表達(dá)式語(yǔ)句5{}函數(shù)由“%”和格式字符&getchar()1027,33,1b11x(1)=x(2)=125+6程序閱讀題1、p=p=p=p=p=p=2、a----ASCII:97a----ASCII:97a----ASCII:97編程題1、#include<>main(){inta,b;floatr1,r2;scanf("%d%d",&a,&b);r2=a+b;r1=a*b/r2;printf("r1=%0.2f,r2=%0.2f\n",r1,r2);}2、#include<>main(){floatc,f;printf("InputC=");scanf("%f",&c);f=5*c+32;printf("F=%f\n",f);}3、#include<>voidmain(){floatc1,c2,c3,ver,s;printf("Inputa,bandc:");scanf("%f%f%f",&c1,&c2,&c3);s=c1+c2+c3;ver=s/3;printf("totals=%f,ver=%f\n",s,ver);}}第4章習(xí)題參照答案判斷題1
2
3
4
5
6×
×
√
√
×
√選擇題1B
2B
3B
4B
5D
6A
7B
8B程序閱讀題1)1052)a=83)abc123DEF4)程序填空題(1)ch(2)div=n(3)min=mark
ch==')'div—min=mark
count--max=mark
count==0sum+=mark
count>0編程題(1)#include<>voidmain(){intx,y;printf("EntertheX,Y=?\n");scanf("%d,%d",&x,&y);if(x>0&&y>0)printf("(%d,%d)是第一像限\n",x,y);elseif(x>0&&y<0)printf("(%d,%d)是第四像限\n",x,y);elseif(x<0&&y>0)printf("(%d,%d)是第三像限\n",x,y);elseif(x<0&&y<0)printf("(%d,%d)是第二像限\n",x,y);elseif(x>0&&y==0)printf("(%d,%d)在X軸正方向\n",x,y);elseif(x<0&&y==0)printf("(%d,%d)在X軸負(fù)方向\n",x,y);elseif(x==0&&y>0)printf("(%d,%d)在Y軸正方向\n",x,y);elseif(x==0&&y<0)printf("(%d,%d)在Y軸負(fù)方向\n",x,y);elseprintf("(%d,%d)為坐標(biāo)原點(diǎn)\n",x,y);}2)#include<>#include<>main(){floata,b,c,x,s;printf("Inputa,bandc:");scanf("%f%f%f",&a,&b,&c);if(a+b<=c||a+c<=b||b+c<=a)printf("Error!\n");else{x=(a+b+c)/2;s=sqrt(x*(x-a)*(x-b)*(x-c));printf("area=%f\n",s);}}(3)程序代碼以下:#include<>voidmain(){floatsalary,tax;intntax;printf("\nPleaseenterasalary=");scanf("%f",&salary);ntax=salary/500;if(ntax>=10)ntax=10;switch(ntax){case0:case1:tax=0;break;case2:tax=(salary-1000)*;break;case3:case4:tax=500*+(salary-1500)*;break;case5:case6:tax=500*+1000*+(salary-2500)*;break;case7:case8:case9:tax=500*+1000*+1000*+(salary-3500)*;break;case10:tax=500*+1000*+1000*+1500*+(salary-5000)*;}printf("\nThetax=%10.2f\n",tax);}4)方法一#include<>#include<>main(){inti=1;floatt=-1,s=0;do{t=-t/i;s=s+t;i=i+1;}while(fabs(t)>1e-6);printf("s=%f\n",s);}方法二#include<>voidmain(){inti=1,sign=1;floatt=,s=;whilet>1e-6){t=t*i;s=s+sign/t;i=i+1;sign=-sign;};printf("s=%f\n",s);}(5)方法一:#include<>main(){inti,a,b,c;for(i=100;i<=999;i++){a=i/100;b=i/10%10;c=i%10;if(i==a*a*a+b*b*b+c*c*c)printf("%d\n",i);}}方法二:#include<>voidmain(){inti,a,b,c;for(a=1;a<=9;a++)for(b=0;b<=9;b++)for(c=0;c<=9;c++){i=a*100+b*10+c;if(i==a*a*a+b*b*b+c*c*c)printf("%d\n",i);}}6)#include<>main(){inti,j;for(i=1;i<=4;i++){for(j=1;j<=6-i;j++)putchar('');for(j=1;j<=i*2-1;j++)printf("%c",65+i-1);printf("\n");}for(i=3;i>=1;i--){for(j=1;j<=6-i;j++)putchar('');for(j=1;j<=i*2-1;j++)printf("%c",65+i-1);printf("\n");}}7)#include<>main(){inta,b,c;for(a=0;a<=20;a++)for(b=0;b<=33;b++){c=100-a-b;if(a*5+b*3+c/==100)printf("%d,%d,%d\n",a,b,c);}}8)#include<>#include<>main(){floatx,x0,a;scanf("%f",&a);x=a;do{x0=x;x=2/*x0+a/(3*x0*x0);}while(fabs(x-x0)>1e-6);printf("x=%f\n",x);}9)#include<>#include<>main(){floatpi,pi0;inti=1pi=2;do{pi0=pi;pi=pi**i/*i-1))**i/*i+1));i=i+1;}while(fabs(pi-pi0)>1e-6);printf("pi=%f\n",pi);}(10)#include<>voidmain(){inti,j,s;for(i=6;i<=1000;i++){s=1;for(j=2;j<=i/2;j++)if(i%j==0)s+=j;if(s==i)/*判斷是否是合數(shù)*/{printf("%d=1",i);/*打印輸出合數(shù)及for(j=2;j<=i/2;j++)/*打印輸出各因子
=1*/*/if(i%j==0)printf("+%d",j);printf("\n");}}}(11)#include<>#include<>voidmain(){intx,y,z,k;k=sqrt(2000);for(x=0;x<=k;x++)for(y=0;y<=k;y++)for(z=0;z<=k;z++)if(x*x+y*y+z*z==2000)printf("%d,%d,%d\n",x,y,z);}第5章習(xí)題參照答案判斷題1
2
3
4
5
6
7
8
9
10111213
1415√×
√×
×√×
××
××
××
××填空題1)322)43)str1[7]='\0';4)for(i=1;i<=6;i++)gets(a[i]);5)strcpy(web,"");6)int*p=a;7)58)19)*(p+6)或*(s+6)選擇題1B
2C
3B
4A
5B
6C
7B
8A
9C
10D
11B
12D
13B
14A
15D程序閱讀題1)62)str3)604)bcdefgacdefgabdefgabc5)a1e25程序填空題(1)#include<>scanf("%f",&a[i])(2)scanf("%d",&n)a[i][i]=1(3)b[i]!='\0'strcpyputs(b)(4)p=a[0];或p=&a[0][0];*p六、編程題1、使用數(shù)組和指針2種方法來(lái)辦理。
s=0;a[i-1][j-1]
x=a[0]printf("\n")
fabs(a[i]-s)方法一(使用數(shù)組)#include<>voidmain(){inti=0,a[10],t;printf("Enterthe10number=\n");for(i=0;i<10;i++)scanf("%d",&a[i]);for(i=0;i<5;i++){t=a[i];a[i]=a[9-i];a[9-i]=t;}for(i=0;i<10;i++)printf("%d",a[i]);printf("\n");}方法二(使用指針)#include<>voidmain(){inti=0,a[10],t,*p,*q;printf("Enterthe10number=\n");for(p=a;p<a+10;p++)scanf("%d",p);p=a;q=a+9;for(;p<q;p++,q--){t=*p;*p=*q;*q=t;}for(p=a;p<a+10;p++)printf("%d",*p);printf("\n");}2、#include<>main(){inti,j,t,n,a[11]={0,1,2,3,4,5,6,7,8,9,10};for(i=0;i<10;i++)printf("%d",a[i]);printf("\n");printf("EntertheMoven=?");scanf("%d",&n);for(i=1;i<=n;i++){t=a[10];for(j=9;j>=0;j--)a[j+1]=a[j];a[0]=t;}for(i=0;i<=10;i++)printf("%d",a[i]);getch();}3、#include<>#include<>main(){inta[100],b[100],i,j,p,n=0,t;randomize();for(i=0;i<100;i++){a[i]=random(100);if(a[i]%2==0)b[n++]=a[i];}for(i=0;i<n-1;i++){p=i;for(j=i+1;j<n;j++)if(b[j]>b[p])p=j;t=b[p];b[p]=b[i];b[i]=t;}for(i=0;i<n;i++){printf("%d",b[i]);if(i%10==9)printf("\n");}getch();}4、#include<>#include<>#defineN50main(){inta[N],i,j,p,t;randomize();for(i=0;i<N;i++){a[i]=random(100);for(j=0;j<i;j++)if(a[i]==a[j]){i--;break;}}for(i=0;i<N-1;i++){p=i;for(j=i+1;j<N;j++)if(a[j]>a[p])p=j;t=a[p];a[p]=a[i];a[i]=t;}for(i=0;i<N;i++){printf("%d",a[i]);if(i%10==9)printf("\n");}}4,#include<>#defineN10voidmain(){inti;floata[N],s=,x0=;for(i=0;i<N;i++){scanf("%f",&a[i]);x0+=a[i];}x0/=N;for(i=0;i<N;i++)s+=(a[i]-x0)*(a[i]-x0);printf("%10.6f",s);}5,#defineN4#defineM3voidmain(){inti,j,sum,a[N][M+1],max,p;printf("inputscore\n");for(i=0;i<N;i++){sum=0;for(j=0;j<M;j++){scanf("%d",&a[i][j]);sum=sum+a[i][j];
/*i代表學(xué)生序號(hào)*//*每位學(xué)生成績(jī)輸入前,其總成績(jī)賦初值/*j代表課程代號(hào)*//*輸入第i號(hào)學(xué)生第j門(mén)課程的成績(jī)*//*累加求總成績(jī)*/
0*/}a[i][M]=sum;
/*求第
i個(gè)學(xué)生的總成績(jī)放到
a[i][M]*/}max=a[0][M];p=0;for(i=1;i<N;i++)
/*查找總成績(jī)最高的學(xué)生
*/if(a[i][M]>max)p=i;printf("No.%dTotalscore:%d\n",p+1,a[p][M]);}7、#include<>voidmain(){inta[5][6];inti,j,mi,mj;for(i=0;i<5;i++)for(j=0;j<6;j++){printf("inputa[%d][%d]:",i,j);scanf("%d",&a[i][j]);}mi=0;mj=0;for(i=0;i<5;i++){for(j=0;j<6;j++){if(a[i][j]<a[mi][mj]){mi=i;mj=j;}printf("%d",a[i][j]);}printf("\n");}printf("min=%d",a[mi][mj]);}6,#include<>#include<>voidmain(){floata[5][6];inti,j,max;printf("Enterarraya=?\n");for(i=0;i<5;i++)for(j=0;j<6;j++)scanf("%f",&a[i][j]);for(i=0;i<5;i++){max=a[i][0];for(j=0;j<6;j++)/*查找第i行中絕對(duì)值最大的元素*/if(fabs(a[i][j])>fabs(max))max=a[i][j];for(j=0;j<6;j++)/*第i行中所有元素除以絕對(duì)值最大的元素
*/{a[i][j]=a[i][j]/max;printf("%",a[i][j]);}printf("-----max=%\n",max);}}7,#include<>#include<>#defineN20main(){charstr[N][15],st[15],*p=st;inti,j;for(i=0;i<N;i++)scanf("%s",str[i]);for(i=0;i<N;i++)for(j=0;j<N-i-1;j++)if(strcmp(str[j],str[j+1])>0){strcpy(p,str[j]);strcpy(str[j],str[j+1]);strcpy(str[j+1],p);}for(i=0;i<N;i++)printf("%s\n",str[i]);}10、程序以下:#include<>main(){inta[10],b[10],t;intn=0,m=0,i,j,f;printf("InputArraya,endwith–1:");scanf("%d",&t);while(n<10&&t!=-1){a[n++]=t;scanf("%d",&t);}printf("InputArrayb,endwith–1:");scanf("%d",&t);while(m<10&&t!=-1){b[m++]=t;scanf("%d",&t);}for(i=0;i<n;i++)/*打印只在數(shù)組{
a中出現(xiàn)的元素
*/f=1;for(j=0;j<m;j++)if(a[i]==b[j]){f=0;break;}if(f)printf("%d",a[i]);}for(i=0;i<m;i++)/*打印只在數(shù)組b中出現(xiàn)的元素*/{f=1;for(j=0;j<n;j++)if(b[i]==a[j]){f=0;break;}if(f)printf("%d",b[i]);}}11、#include<>main(){charstr[81];inti=-1;printf("Input:");scanf("%s",str);while(++i<80&&str[i]!='\0')if(str[i]=='$')str[i]='S';puts(str);}12、#include<>voidmain(){charx[80],y[26];inti,j,ny=0;gets(x);for(i=0;x[i]!='\0';i++)if(x[i]>='A'&&x[i]<='Z'){for(j=0;j<ny;j++)if(y[j]==x[i])break;if(j==ny){y[ny]=x[i];ny++;}}for(i=0;i<ny;i++)printf("%c",y[i]);printf("\n");}13、#include<>voidmain(){intm,bin[32],j;scanf("%d",&m);for(j=0;m!=0;j++){bin[j]=m%2;m=m/2;}for(;j!=0;j--)printf("%d",bin[j-1]);}14、#include<>#include<>#include<>voidmain(){chars[80];inti=0;gets(s);while(s[i]!='\0')if(isdigit(s[i]))strcpy(s+i,s+i+1);elsei++;puts(s);}15、voidmain(){inta,b,c;int*p1,*p2,*p3,*t;printf("\nPleaseinputthreeintegers:\n");scanf("%d,%d,%d",&a,&b,&c);p1=&a,p2=&b,p3=&c;if(*p1>*p2)t=p1,p1=p2,p2=t;if(*p1>*p3)t=p1,p1=p3,p3=t;if(*p2>*p3)t=p2,p2=p3,p3=t;printf("neworder:\n");printf("%d,%d,%d",*p1,*p2,*p3);}16、voidmain(){charst[80],ss[20],sp[20],*a=st,*b=ss,*t=sp;inti,n,m,p=-1;printf("\nPleaseinputtwostring:\n");gets(a);gets(b);n=strlen(a);m=strlen(b);for(i=0;i<=n-m+1;i++){a=st+i;strncpy(t,a,m);
/*將字符指針
a指向的字符串取前
m個(gè)字符復(fù)制到
t所指的字符串中*/if(strcmp(b,t)==0){p=i;break;}}if(p==-1)printf("%d",p);elseprintf("%d",p+1);
/*因數(shù)組下標(biāo)從
0開(kāi)始,所以輸出
p+1*/getch();}17、#include<>voidmain(){charst[80],*p=st,ch;printf("Enterastring\n");gets(p);while(*p!='\0'){ch=*p;if(ch>='A'&&ch<='Z')ch='A'+('Z'-ch);elseif(ch>='a'&&ch<='z')ch='a'+('z'-ch);*p=ch;/*變換后的字符代替原字符p++;/*指針指向下一個(gè)字符*/}/*指針指向字符串首字符
*/
*/p=st;puts(p);getch();}18、#include<>voidmain(){charst[80],*p=st,ch;longk=0;printf("Enterastring\n");gets(p);strupr(p);while(*p!='\0'){ch=*p;if(ch>='0'&&ch<='9'||ch>='A'&&ch<='F')p++;elsestrcpy(p,p+1);/*濾去所有的非十六進(jìn)制字符*/}p=st;while(*p!='\0')/*將十六制數(shù)變換成十進(jìn)數(shù)*/{ch=*p;if(ch>='0'&&ch<='9')k=16*k+(ch-'0');elseif(ch>='A'&&ch<='F')k=16*k+(10+ch-'A');p++;}printf("%ld\n",k);}第6章習(xí)題參照答案判斷題1
2
3
4
5
6
7
8
9
10×
×
√
√
×
√
×
×
×
×選擇題1C
2B
3A
4C
5D填空題1)char*printch(int,char);2)intstrlen(char*);3)intmin(int*);4)intrandom(void);5)intdigits(double,int);程序閱讀題1)(127)10=(7F)16(2)303)a=64,b=64(4)(3,6)程序填空題(1)random(10)+’0’s,N,c(2)int*mx<v[k]v[k+1](3)sign=-1digit=0digit=digit*10+(s[k]-(4){,,,,}floatx,float*a,intnreturny
a[I]-
‘0’
‘0’)編程題(1)#include<>intjfnum(intn);main(){inti;for(i=100;i<=999;i++)if(judge(i))printf("%d\n",i);}intjudge(intn){intn1,n2,n3,flag;if(n<100||n>999)printf("error!");else{n1=n%10;n2=(n/10)%10;n3=n/100;if(n==n1*n1*n1+n2*n2*n2+n3*n3*n3)flag=1;elseflag=0;}return(flag);}2)floatmysqr(floata,floateps){floatx0,x1,t;if(a<0)printf("error!");else{x0=a/;do{x1=(x0+a/x0)/;t=fabs(x1-x0);x0=x1;}while(t>eps);}return(x1);}3)voidcode(chars[],intn){inti;for(i=0;i<n;i++)if('A'<=s[i]&&s[i]<='Z'||'a'<=s[i]&&s[i]<='z'){s[i]=s[i]+5;if(s[i]>'z'||s[i]>'Z'&&s[i]<'a')s[i]=s[i]-26;}}voidrecode(chars[],intn){inti;for(i=0;i<n;i++)if('A'<=s[i]&&s[i]<='Z'||'a'<=s[i]&&s[i]<='z'){s[i]=s[i]-5;if(s[i]<'A'||s[i]<'a'&&s[i]>'Z')s[i]=s[i]+26;}}4)intleapyear(intyear);main(){intyear;printf("Inputyearnumber:");scanf("%d",&year);if(leapyear(year)==1)printf("\n%disleapyear\n",year);elseprintf("\n%disnotleapyear\n",year);}intleapyear(intyear){if(year%4==0&&year%100!=0||year%400==0)return(1);elsereturn(0);}5)#include<>char*search(char*s,charc){intflag;flag=0;while(*s!='\0'){if(*s==c){flag=1;break;}s++;}if(flag==1)return(s);elsereturn(NULL);}6)#include<>voidmaxmin(inta,intb,intc,int*max,int*min);main(){inta,b,c,max,min;printf("\nPleaseinputthreeintegers:\n");scanf("%d,%d,%d",&a,&b,&c);maxmin(a,b,c,&max,&min);printf("max=%d,min=%d",max,min);}voidmaxmin(inta,intb,intc,int*max,int*min){if(a>b){*max=a;*min=b;}if(c>*max)*max=c;if(c<*min)*min=c;}(7)#include<>#include<>voidgetdata(inta[],intn);/*隨機(jī)生成數(shù)據(jù)函數(shù)的原型聲明*/voidprintdata(inta[],intn);/*輸出數(shù)據(jù)函數(shù)原型聲明*/voidsort(inta[],intn);/*排序函數(shù)原型聲明*/floataverage(inta[],intn);/*求平均值函數(shù)原型聲明*/voidcount(inta[],intn,floatx,intb[]);
/*統(tǒng)計(jì)函數(shù)原型聲明
*/main(){inta[20],b[3];floatx;getdata(a,20);printf("\nInitialize:\n");printdata(a,20);sort(a,20);printf("\nSort:\n");printdata(a,20);x=average(a,20);printf("\nAverage:%f\n",x);count(a,20,x,b);printf("\n>=<:\n");printdata(b,3);}voidgetdata(inta[],intn){inti;randomize();for(i=0;i<n;i++)a[i]=(rand()%90)+10;}voidprintdata(inta[],intn){inti;for(i=0;i<n;i++){if(i%5==0)printf("\n");printf("%d",a[i]);}}voidsort(inta[],intn){inti,j,k,t;for(i=0;i<n-1;i++){k=i;for(j=i+1;j<n;j++)if(a[k]>a[j])k=j;t=a[i];a[i]=a[k];a[k]=t;}}floataverage(inta[],intn){floats;inti;s=;for(i=0;i<n;i++)s=s+a[i];return(s/n);}voidcount(inta[],intn,floatx,intb[]){inti;b[0]=b[1]=b[2]=0;for(i=0;i<n;i++)if(a[i]>x)b[0]++;elseif(a[i]==x)b[1]++;elseb[2]++;}8)#include""voidinvert(char*string){intn;char*h,*t,c;n=strlen(string);h=string;t=h+n-1;while(h<t){c=*h;*h=*t;*t=c;h++;t--;}}9)voidmystrcpy(char*s1,char*s2,intm){s2=s2+m-1;while(*s2!='\0'){*s1=*s2;s1++;s2++;}*s1='\0';}10)intf(intn){if(n<0)printf("error");else{if(n==0)return0;elseif(n==1)return1;elsereturnf(n-2)+f(n-1);}}11)方法一、使用循環(huán)#include""#include""floatyx(floatx){floaty0,y1;if(x<0)printf("error");else{y0=sqrt(x);y1=sqrt(x+y0);while(fabs(y1-y0)>{y0=y1;y1=sqrt(x+y0);}}returny1;}方法二:使用遞歸方法#include<>#include<>doublefunc(intxcount,doublex)/*xcount是根號(hào)的個(gè)數(shù)*/{doubley=0;if(xcount==1)y=sqrt(x);elsey=sqrt(func(xcount-1,x)+x);returny;}voidmain(){intxcount;doubleresult,x;scanf("%d%lf",&xcount,&x);if(x<=0)/*x小于0出錯(cuò)*/printf("DateError!");elseprintf("%lf",func(xcount,x));getch();}12)#include""voidmaxa(inta[3][4]);voidverse(inta[3][4]);voidmain(){inti,j,a[3][4];for(i=0;i<3;i++)for(j=0;j<4;j++)scanf("%d",&a[i][j]);maxa(a);verse(a);getch();}voidmaxa(inta[3][4]){inti,j,imax=0,jmax=0;for(i=0;i<3;i++)for(j=0;j<4;j++)if(a[i][j]>a[imax][jmax]){imax=i;jmax=j;}printf("Themaxnumberisa[%d][%d]=%d\n",imax,jmax,a[imax][jmax]);}voidverse(inta[3][4]){inti,j,imax=0,jmax=0;for(j=0;j<4;j++){for(i=0;i<3;i++)printf("%d",a[i][j]);printf("\n");}}第7章習(xí)題參照答案判斷題1
2
3
4
5
6√
×
×
√
×
×選擇題1B
2B
3C
4D
5B
6A填空題1)程序編譯從前2)#include“”3)c=c-324)25)5316)z=0編程題1)#include<>#defineRN(x)if(x%4==0&&x%100!=100||x%400==0)printf("YES");elseprintf("NO");voidmain(){intn;scanf("%d",&n);RN(n)}2)#include<>#defineMIN(x,y,z)printf("%d",(x<y?x:y)<z?(x<y?x:y):z);voidmain(){inta,b,c;scanf("%d%d%d",&a,&b,&c);MIN(a,b,c)}3)#include<>#defineINPUT(a,n)for(i=0;i<n;i++)scanf("%f",&a[i]);#defineAVERAGE(a,n,ave)for(i=0;i<n;i++)ave+=a[i];voidmain(){floata[5],ave=0;inti;INPUT(a,5)AVERAGE(a,5,ave)printf("%f",ave/10);}第8章習(xí)題參照答案1.思慮題(略)2.判斷題:123456√×××√√3.選擇題12345678ADDBDADD4.程序閱讀1)2,4,6,8,10,。2)(3)Shen。(4)18。(5)1-575.程序填空(1)p->next!=NULLinfop=p->next;(2)p1->next!=NULLp0->next=p1;p0->next=NULL;(3)s[k].avers[k].aver>s[maxsub].avermaxsub=k(4)max=i;min=i;stud[max].name,stud[max].scorestud[min].name,stud[min].score5)headn++p->next6.編程題1)structcomplx{intreal;intim;};main(){structcomplxc1,c2,c3;scanf("%d+%di",&,&;scanf("%d+%di",&,&;=*=*+*;printf("(%d+%di)*(%d+%di)=%d+%di",,,,,,;getch();}(2)#include<>#include<>main()#defineN10structstudent{longnum;charname[10];floatscore[3];floatave;};main(){voidinput(structstudents[],intn);/*輸入n個(gè)學(xué)生數(shù)據(jù)*/floataverage(structstudents[],intn);/*計(jì)算第n個(gè)學(xué)生的平均成績(jī)*/intmax(structstudents[],intn);/*計(jì)算n個(gè)學(xué)生中哪個(gè)學(xué)生的平均成績(jī)最高structstudents[N];
*/inti,m;floata=0;/*總平均成績(jī)*/input(s,N);for(i=0;i<N;i++){s[i].ave=average(s,i);a=a+s[i].ave;}a=a/N;printf("NumberNameScore-1Score-2Score-3Average\n");for(i=0;i<N;i++)printf("%ld%10s%f%f%f%f\n",s[i].num,s[i].name,s[i].score[0],s[i].score[1],s[i].score[2],s[i].ave);printf("Thetotalaveragescoreis%f\n",a);m=max(s,N);printf("Themaxscorestudent:\n");printf("Number:%ld\nName:%s\nScore1:%f\nScore2:%f\nScore3:%f\nAverageScore:%f\n",s[m].num,s[m].name,s[m].score[0],s[m].score[1],s[m].score[2],s[m].ave);}voidinput(structstudents[],intn){inti;for(i=0;i<n;i++){printf("Pleaseinputstudentnumber:");scanf("%ld",&s[i].num);printf("Pleaseinputstudentname:");scanf("%s",s[i].name);printf("Pleaseinputstudentscore1:");scanf("%f",&s[i].score[0]);printf("Pleaseinputstudentscore2:");scanf("%f",&s[i].score[1]);printf("Pleaseinputstudentscore3:");scanf("%f",&s[i].score[2]);}}floataverage(structstudents[],intn){inti;floata=0;for(i=0;i<3;i++)a=a+s[n].score[i];a=a/3;return(a);}intmax(structstudents[],intn){inti,m=0;for(i=1;i<n;i++)if(s[i].ave>s[m].ave)m=i;return(m);}3)structdate{intyear;intmonth;intday;};intdays(structdated){intn,t;if%4==0&&%100!=0||%400==0)t=29;elset=28;switch{case1:n=;break;case2:n=+31;break;case3:n=+31+t;break;case4:n=+31+t+31;break;case5:n=+31+t+31+30;break;case6:n=+31+t+31+30+31;break;case7:n=+31+t+31+30+31+30;break;case8:n=+31+t+31+30+31+30+31;break;case9:n=+31+t+31+30+31+30+31+31;break;case10:n=+31+t+31+30+31+30+31+31+30;break;case11:n=+31+t+31+30+31+30+31+31+30+31;break;case12:n=+31+t+31+30+31+30+31+31+30+31+30;}return(n);}main(){structdated={2006,3,15};printf("%d",days(d));getch();}4)structks{intreg;char*name;charsex;char*birthday;intscore[6];};structksinput(){structkss;inti,sum=0;printf("register:");scanf("%d",&;printf("name:");scanf("%s",;printf("sex:");scanf("%c",&;printf("birthday:");scanf("%s",;for(i=0;i<5;i++){printf("score-%d:",i+1);scanf("%d",&[i]);sum=sum+[i];}[5]=sum;return(s);}voidprint(structkss){inti;printf("register:%d\n",;printf("name:%s\n",;printf("sex:%c\n",;printf("birthday:%s\n",;for(i=0;i<5;i++)printf("score-%d:%d\n",i+1,[i]);printf("sum:%d\n",[5]);getch();}structkssearch(structkss[],intn){inti,p=0;for(i=1;i<n;i++)if(s[i].score[5]>s[p].score[5])p=i;return(s[p]);}voidsort(structkss[],intn){inti,j,p;structkst;for(i=0;i<n-1;i++){p=i;for(j=i+1;j<n;j++)if(s[j].reg<s[p].reg)p=j;t=s[i];s[i]=s[p];s[p]=t;print(s[i]);}print(s[n-1]);}5)#defineNULL0#defineLENsizeof(structstudent)structstudent{longnum;charname[10];charsex;/*'F'表示女,'M'表示男*/intage;structstudent*next;}main(){structstudent*creat(intn);voidprint(structstudent*head);structstudent*delete(structstudent*head,intage);structstudent*head;intn,age;printf("\nPleaseinputthelengthoflist:");scanf("%d",&n);head=creat(n);print(head);}structstudent*creat(intn){structstudent*head,*p1,*p2;inti;head=NULL;for(i=1;i<=n;i++){p1=(structstudent*)malloc(LEN);printf("Number:");scanf("%ld",&p1->num);printf("Name:");scanf("%s",p1->name);printf("Sex:");scanf("%c",&p1->sex);printf("Age:");scanf("%d",&p1->age);if(i==1)head=p1;elsep2->next=p1;p2=p1;}p2->next=NULL;return(head);}voidprint(structstudent*head){structstudent*p;p=head;printf("NumberNameSexAge\n");while(p!=NULL){printf("%ld%10s%c%d",p->num,p->name,p->sex,p->age);p=p->next;}}6)structstudent*delete(structstudent*head,intage){structstudent*p1,*p2;p1=head;while(p1!=NULL){if(p1->age==age){if(p1==head)head=p1->next;elsep2->next=p1->next;free(p1);}p2=p1;p1=p1->next;}return(head);}第9章習(xí)題參照答案填空題7)文本文件/二進(jìn)制文件8)創(chuàng)辦a文件9)打開(kāi)a文件,并且文件讀寫(xiě)地址指針在文件尾(10)將字符變量ch中的字符寫(xiě)入fp所指向的文件/從fp所指向的文件中讀取n-1個(gè)字符,并且寫(xiě)入數(shù)組s中(11)0(12)for(i=0;i<30;i++)fread(&stud[i],sizeof(structstudent_type),1,fp)13)fseek(fp,30L,SEEK_SET)14)-1選擇題1
2
3
4
5
6
7
8A
B
C
D
C
C
D
C程序閱讀題-5,-4,-3,-2,total=-14Language!123453678910程序填空題1(fp=fopen("c:\\","w"))(ch=getchar())fputc(ch,fp)stu[i].name,stu[i].sno,stu[i].age,stu[i].address2"w"&stu[i],sizeof(structstudent),1,fpr3w編程題(1)#include<>voidmain(){FILE*fp1,*fp2;charch;if((fp1=fopen("C:\\Mydir\\","r"))==NULL){printf("Cannotopenfilestrikeanykeyexit!");exit(0);}if((fp2=fopen("C:\\Mydir\\","w"))==NULL){printf("Cannotopenfilestrikeanykeyexit!");exit(0);}while((ch=fgetc(fp1))!=EOF){if(ch>='A'&&ch<='Z')ch+=32;elseif
(ch>='a'&&ch<='z')ch-=32;fputc(ch,fp2);}
;fclose(fp1);fclose(fp2);remove("C:\\Mydir\\");rename("C:\\Mydir\\","C:\\Mydir\\");}(2)#include<>intsearch(FILE*fp,charch);voidmain(){FILE*fp;charfilename[30];charch;intcount;printf("Pleseinputfilename:\n");gets(filename);printf("Pleseinputthecharacteryouwanttosearch:\n");scanf("%c",&ch);if((fp=fopen(filen
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 商務(wù)接待用車(chē):汽車(chē)租賃合同
- 醫(yī)療機(jī)構(gòu)麻醉科醫(yī)師聘用協(xié)議
- 圖書(shū)館管理員聘用合同樣本
- 鐵路線路新建爆破工程合同
- 污水處理廠環(huán)保設(shè)施技術(shù)升級(jí)合同
- 水電站建設(shè)河道施工合同
- 網(wǎng)絡(luò)安全工程師聘用合同
- 辦公大樓鋼結(jié)構(gòu)施工承包合同
- 幼教中心綠化養(yǎng)護(hù)合同
- 電影院入口廣告牌施工合同
- 電子銀行案防自我評(píng)估報(bào)告
- 體育教研室教學(xué)大綱-身體運(yùn)動(dòng)功能訓(xùn)練
- 腫瘤微環(huán)境與結(jié)直腸癌
- 液壓與氣壓傳動(dòng)課程設(shè)計(jì)
- 專(zhuān)題05 探索與表達(dá)規(guī)律(解析版)
- 重慶醫(yī)科大學(xué)人體機(jī)能學(xué)實(shí)驗(yàn)報(bào)告
- 中金所杯全國(guó)大學(xué)生金融知識(shí)大賽題庫(kù)及答案(單選題)
- 疼痛科護(hù)士職業(yè)規(guī)劃書(shū)
- 靜壓樁基施工安全技術(shù)交底
- YY/T 0698.5-2023最終滅菌醫(yī)療器械包裝材料第5部分:透氣材料與塑料膜組成的可密封組合袋和卷材要求和試驗(yàn)方法
- 汽機(jī)專(zhuān)業(yè)小口徑管道施工規(guī)范及工藝要求
評(píng)論
0/150
提交評(píng)論