版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
..第1章習(xí)題參考答案1.〔略判斷題12345√×√×√填空題main函數(shù)的首部、函數(shù)體{、}main、main語句、分號〔;選擇題12345CCCAB選擇題#include<stdio.h>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>;}#include<stdio.h>main<>{printf<"=================\n">;printf<"Hello!\n">;printf<"Howdoyoudo\n">;printf<"=================\n">;}〔3#include<stdio.h>main<>{intr,h;floatv;printf<"EnterR,H=?\n">;scanf<"%d%d",&r,&h>;v=3.1415926*r*r*h;printf<"v=%f\n",v>;}第2章習(xí)題參考答案一.〔略二.填空題2.5161016、16、114、10、618、3、3sin<65*3.14/180>+2*〔3.1415926+exp<y>/<x-y>25、252740選擇題123456789101112DDCBDADBCDAB四、編程題1.#include<stdio.h>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<stdio.h>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<stdio.h>main<>{floata,b,h,s;scanf<"%f%f?%f",&a,&b,&h>;s=<a+b>*h/2;printf<"s=%f\n",s>;}第3章習(xí)題參考答案一、判斷題123456×××√√×填空題語句表達式語句{}函數(shù)由"%"和格式字符&getchar<>27,33,1bx<1>=23.14x<2>=-78.325+6程序閱讀題1、p=3.14p=3.1416p=3.14p=3.1416p=3.14p=3.14162、a----ASCII:97a----ASCII:97a----ASCII:97編程題1、#include<stdio.h>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<stdio.h>main<>{floatc,f;printf<"InputC=">;scanf<"%f",&c>;f=9.0/5*c+32;printf<"F=%f\n",f>;}3、#include<stdio.h>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í)題參考答案判斷題123456××√√×√選擇題12345678BBBBDABB程序閱讀題105a=8abc123DEF程序填空題chch=='>'count--count==0count>0div=n div—min=markmin=markmax=marksum+=mark編程題#include<stdio.h>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軸負方向\n",x,y>;elseif<x==0&&y>0>printf<"<%d,%d>在Y軸正方向\n",x,y>;elseif<x==0&&y<0>printf<"<%d,%d>在Y軸負方向\n",x,y>;elseprintf<"<%d,%d>為坐標原點\n",x,y>;}#include<stdio.h>#include<math.h>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<stdio.h>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>*0.05;break;case3:case4:tax=500*0.05+<salary-1500>*0.1;break;case5:case6:tax=500*0.05+1000*0.1+<salary-2500>*0.15;break;case7:case8:case9:tax=500*0.05+1000*0.1+1000*0.15+<salary-3500>*0.20;break;case10:tax=500*0.05+1000*0.1+1000*0.15+1500*0.20+<salary-5000>*0.30;}printf<"\nThetax=%10.2f\n",tax>;}〔4方法一#include<stdio.h>#include<math.h>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<stdio.h>voidmain<>{inti=1,sign=1;floatt=1.0,s=0.0;while<1.0/t>1e-6>{t=t*i;s=s+sign/t;i=i+1;sign=-sign;};printf<"s=%f\n",s>;}〔5方法一:#include<stdio.h>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<stdio.h>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<stdio.h>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<stdio.h>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/3.0==100>printf<"%d,%d,%d\n",a,b,c>;}}〔8#include<stdio.h>#include<math.h>main<>{floatx,x0,a;scanf<"%f",&a>;x=a;do{x0=x;x=2/3.0*x0+a/<3*x0*x0>;}while<fabs<x-x0>>1e-6>;printf<"x=%f\n",x>;}〔9#include<stdio.h>#include<math.h>main<>{floatpi,pi0;inti=1pi=2;do{pi0=pi;pi=pi*<2.0*i/<2.0*i-1>>*<2.0*i/<2.0*i+1>>;i=i+1;}while<fabs<pi-pi0>>1e-6>;printf<"pi=%f\n",pi>;}〔10#include<stdio.h>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ù)及=1*/for<j=2;j<=i/2;j++>/*打印輸出各因子*/if<i%j==0>printf<"+%d",j>;printf<"\n">;}}}<11>#include<stdio.h>#include<math.h>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í)題參考答案判斷題123456789101112131415√×√××√×××××××××填空題324str1[7]='\0';for<i=1;i<=6;i++>gets<a[i]>;strcpy<web,"">;int*p=a;51*<p+6>或*<s+6>選擇題123456789101112131415BCBABCBACDBDBAD程序閱讀題6str60bcdefgacdefgabdefgabca1e2程序填空題#include<math.h>scanf<"%f",&a[i]>s=0;x=a[0]fabs<a[i]-s>scanf<"%d",&n>a[i][i]=1a[i-1][j-1]printf<"\n">b[i]!='\0'strcpyputs<b>〔4p=a[0];或p=&a[0][0];*p六、編程題1、使用數(shù)組和指針2種方法來處理。方法一〔使用數(shù)組#include<stdio.h>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<stdio.h>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<stdio.h>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<stdio.h>#include<stdlib.h>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<stdio.h>#include<stdlib.h>#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<stdio.h>#defineN10voidmain<>{inti;floata[N],s=0.0,x0=0.0;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++>/*i代表學(xué)生序號*/{sum=0;/*每位學(xué)生成績輸入前,其總成績賦初值0*/for<j=0;j<M;j++>/*j代表課程代號*/{scanf<"%d",&a[i][j]>;/*輸入第i號學(xué)生第j門課程的成績*/sum=sum+a[i][j];/*累加求總成績*/}a[i][M]=sum;/*求第i個學(xué)生的總成績放到a[i][M]*/}max=a[0][M];p=0;for<i=1;i<N;i++>/*查找總成績最高的學(xué)生*/if<a[i][M]>max>p=i;printf<"No.%dTotalscore:%d\n",p+1,a[p][M]>;}7、#include<stdio.h>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<stdio.h>#include<math.h>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行中絕對值最大的元素*/if<fabs<a[i][j]>>fabs<max>>max=a[i][j];for<j=0;j<6;j++>/*第i行中所有元素除以絕對值最大的元素*/{a[i][j]=a[i][j]/max;printf<"%8.4",a[i][j]>;}printf<"-----max=%8.4\n",max>;}}7,#include<stdio.h>#include<string.h>#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<stdio.h>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<stdio.h>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<stdio.h>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<stdio.h>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<stdio.h>#include<string.h>#include<ctype.h>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個字符復(fù)制到t所指的字符串中*/if<strcmp<b,t>==0>{p=i;break;}}if<p==-1>printf<"%d",p>;elseprintf<"%d",p+1>;/*因數(shù)組下標從0開始,所以輸出p+1*/getch<>;}17、#include<string.h>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;/*轉(zhuǎn)換后的字符替換原字符*/p++;/*指針指向下一個字符*/}/*指針指向字符串首字符*/p=st;puts<p>;getch<>;}18、#include<string.h>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>;/*濾去所有的非十六進制字符*/}p=st;while<*p!='\0'>/*將十六制數(shù)轉(zhuǎ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í)題參考答案判斷題12345678910××√√×√××××選擇題12345CBACD填空題char*printch<int,char>;intstrlen<char*>;intmin<int*>;intrandom<void>;intdigits<double,int>;程序閱讀題<127>10=<7F>1630a=64,b=64<3,6>程序填空題random<10>+’0’s,N,ca[I]-‘int*mx<v[k]v[k+1]sign=-1digit=0digit=digit*10+<s[k]-‘0’{1.1,2.2,3.3,4.4,5.5}floatx,float*a,intnreturny編程題〔1#include<stdio.h>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>;}〔2floatmysqr<floata,floateps>{ floatx0,x1,t; if<a<0>printf<"error!">; else { x0=a/2.0; do { x1=<x0+a/x0>/2.0; t=fabs<x1-x0>; x0=x1; }while<t>eps>;} return<x1>;}〔3voidcode<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; }}〔4intleapyear<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<stdio.h>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<stdio.h>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<stdio.h>#include<stdlib.h>voidgetdata<inta[],intn>; /*隨機生成數(shù)據(jù)函數(shù)的原型聲明*/voidprintdata<inta[],intn>; /*輸出數(shù)據(jù)函數(shù)原型聲明*/voidsort<inta[],intn>; /*排序函數(shù)原型聲明*/floataverage<inta[],intn>; /*求平均值函數(shù)原型聲明*/voidcount<inta[],intn,floatx,intb[]>; /*統(tǒng)計函數(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=0.0; 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"string.h"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--;}}〔9voidmystrcpy<char*s1,char*s2,intm>{s2=s2+m-1;while<*s2!='\0'>{*s1=*s2;s1++;s2++;}*s1='\0';}〔10intf<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"stdio.h"#include"math.h"floatyx<floatx>{floaty0,y1;if<x<0>printf<"error">;else{y0=sqrt<x>;y1=sqrt<x+y0>;while<fabs<y1-y0>>0.00001>{y0=y1;y1=sqrt<x+y0>;}}returny1;}方法二:使用遞歸方法#include<stdio.h>
#include<math.h>doublefunc<intxcount,doublex>
/*xcount是根號的個數(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出錯*/
printf<"DateError!">;
else
printf<"%lf",func<xcount,x>>;
getch<>;
}〔12#include"stdio.h"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.判斷題123456√××√××2.選擇題123456BBCDBA填空題程序編譯之前#include"myhead.h"c=c-3225 31z=04.編程題〔1#include<stdio.h>#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<stdio.h>#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<stdio.h>#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.程序閱讀〔12,4,6,8,10,?!?10987654321〔3Shen。〔418。1-51-575.程序填空〔1p->next!=NULLinfop=p->next;〔2p1->next!=NULLp0->next=p1;p0->next=NULL;〔3s[k].avers[k].aver>s[maxsub].avermaxsub=k〔4max=i;min=i;stud[max].name,stud[max].scorestud[min].name,stud[min].score〔5headn++p->next6.編程題〔1structcomplx{intreal;intim;};main<>{structcomplxc1,c2,c3;scanf<"%d+%di",&c1.real,&c1.im>;scanf<"%d+%di",&c2.real,&c2.im>;c3.real=c1.real*c2.real-c1.im*c2.im;c3.im=c1.real*c2.im+c1.im*c2.real;printf<"<%d+%di>*<%d+%di>=%d+%di",c1.real,c1.im,c2.real,c2.im,c3.real,c3.im>;getch<>;}〔2#include<stdio.h>#include<string.h>main<>#defineN10structstudent{ longnum; charname[10]; floatscore[3]; floatave;};main<>{ voidinput<structstudents[],intn>; /*輸入n個學(xué)生數(shù)據(jù)*/ floataverage<structstudents[],intn>;/*計算第n個學(xué)生的平均成績*/ intmax<structstudents[],intn>; /*計算n個學(xué)生中哪個學(xué)生的平均成績最高*/ structstudents[N]; inti,m; floata=0; /*總平均成績*/ input<s,N>; for<i=0;i<N;i++> { s[i].ave=average<s,i>; a=a+s[i].ave; } a=a/N; printf<"Number Name Score-1 Score-2 Score-3 Average\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>; }〔3structdate{intyear;intmonth;intday;};intdays<structdated>{intn,t;if<d.year%4==0&&d.year%100!=0||d.year%400==0>t=29;elset=28;switch<d.month>{case1:n=d.day;break;case2:n=d.day+31;break;case3:n=d.day+31+t;break;case4:n=d.day+31+t+31;break;case5:n=d.day+31+t+31+30;break;case6:n=d.day+31+t+31+30+31;break;case7:n=d.day+31+t+31+30+31+30;break;case8:n=d.day+31+t+31+30+31+30+31;break;case9:n=d.day+31+t+31+30+31+30+31+31;break;case10:n=d.day+31+t+31+30+31+30+31+31+30;break;case11:n=d.day+31+t+31+30+31+30+31+31+30+31;break;case12:n=d.day+31+t+31+30+31+30+31+31+30+31+30;}return<n>;}main<>{structdated={2006,3,15};printf<"%d",days<d>>;getch<>;}〔4structks{intreg;char*name;charsex;char*birthday;intscore[6];};structksinput<>{structkss;inti,sum=0;printf<"register:">;scanf<"%d",&s.reg>;printf<"name:">;scanf<"%s",>;printf<"sex:">;scanf<"%c",&s.sex>;printf<"birthday:">;scanf<"%s",s.birthday>;for<i=0;i<5;i++>{printf<"score-%d:",i+1>;scanf<"%d",&s.score[i]>;sum=sum+s.score[i];}s.score[5]=sum;return<s>;}voidprint<structkss>{inti;printf<"register:%d\n",s.reg>;printf<"name:%s\n",>;printf<"sex:%c\n",s.sex>;printf<"birthday:%s\n",s.birthday>;for<i=0;i<5;i++>printf<"score-%d:%d\n",i+1,s.score[i]>;printf<"sum:%d\n",s.score[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<"Number Name Sex Age\n">; while<p!=NULL> { printf<"%ld%10s%c%d",p->num,p->name,p->sex,p->age>; p=p->next; }}〔6structstudent*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í)題參考答案填空題文本文件/二進制文件創(chuàng)建a文件打開a文件,并且文件讀寫位置指針在文件尾將字符變量ch中的字符寫入fp所指向的文件/從fp所指向的文件中讀取n-1個字符,并且寫入數(shù)組s中0for<i=0;i<30;i++>fread<&stud[i],sizeof<structstudent_type>,1,fp >fseek<fp,30L,SEEK_SET>-1選擇題12345678ABCDCCDC3.程序閱讀題1-5,-4,-3,-2,total=-142Language!3123456789104.程序填空題1<fp=fopen<"c:\\data.txt","w">><ch=getchar<>>fputc<ch,fp>2stu[i].name,stu[i].sno,stu[i].age,stu[i].address"w"&stu[i],sizeof<structstudent>,1,fp3rw5.編程題<1>#include<stdio.h>voidmain<>{FILE*fp1,*fp2;charch;if<<fp1=fopen<"C:\\Mydir\\String.txt","r">>==NULL>{printf<"Cannotopenfilestrikeanykeyexit!">;exit<0>;}if<<fp2=fopen<"C:\\Mydir\\NewString.txt","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\\String.txt">;rename<"C:\\Mydir\\String.txt","C:\\Mydir\\NewString.txt">;}<2>#include<stdio.h>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<
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《社區(qū)足球賽方案》課件
- 《汽車客運站調(diào)研》課件
- 2024年黑龍江林業(yè)職業(yè)技術(shù)學(xué)院單招職業(yè)技能測試題庫完整答案
- 單位管理制度集合大全【人事管理篇】
- 《綜合分析觀點類》課件
- 單位管理制度匯編大全【人員管理】
- 2024的前臺工作計劃(35篇)
- 單位管理制度范文大合集【職工管理篇】
- 單位管理制度范例匯編【人員管理篇】十篇
- 《禽流感的預(yù)防措施》課件
- 2024年安徽省高中語文學(xué)業(yè)水平合格考模擬試卷試題(含答案詳解)
- 流程即組織力(企業(yè)高效增長的業(yè)務(wù)管理邏輯)
- 小學(xué)三年級上冊道德與法治期末測試卷及完整答案(有一套)
- 教師教學(xué)事故檢討書
- 2024年1月自考18960禮儀學(xué)試題及答案含解析
- 鐵工電〔2023〕54號國鐵集團關(guān)于印發(fā)《普速鐵路工務(wù)安全規(guī)則》的通知
- Vue.js前端開發(fā)實戰(zhàn)(第2版)-教學(xué)課件 第1章 初識Vue
- 事業(yè)單位工作人員處分暫行規(guī)定2012
- 事業(yè)單位年度考核實施方案
- CJJ 169-2012城鎮(zhèn)道路路面設(shè)計規(guī)范
- 現(xiàn)代機械工程圖學(xué) 課件 第10章-裝配圖
評論
0/150
提交評論