C语言程序设计课后习题答案吉林大学版武爱平.docx
- 文档编号:8934195
- 上传时间:2023-02-02
- 格式:DOCX
- 页数:39
- 大小:29.81KB
C语言程序设计课后习题答案吉林大学版武爱平.docx
《C语言程序设计课后习题答案吉林大学版武爱平.docx》由会员分享,可在线阅读,更多相关《C语言程序设计课后习题答案吉林大学版武爱平.docx(39页珍藏版)》请在冰豆网上搜索。
C语言程序设计课后习题答案吉林大学版武爱平
第一章1.选择题
(1)B
(2)C(3)C(4)D(5)B(6)D(7)D(8)C
2.填空题
(1)函数
一个主函数
函数
(2)/*
*/
(3)连接
3.程序设计题
(1)
#include
main()
{
printf("*\n");
printf("*S*\n");
printf("*\n");
}
(2)
#include
main()
{
printf("******************\n");
printf("Yourarewelcome!
\n");
printf("------------------\n");
}
第二章
1.选择题
(1)D
(2)D(3)B(4)C(5)B(6)C(7)C(8)C(9)D(10)C(11)A(12)B(13)A(14)C(15)A(16)B(17)A(18)B(19)C(20)A(21)C(22)C
2.填空题
(1)
9
-2
62
44.8
(2)
10.5
73.1
7
7.2
(3)"%6x"
"%o"
"%3c"
"%10.3f"
"%8s"
(4)inta,b,c;
&a,&b,&c
temp=a;
c=temp;
(5)49
61
31
1
3.程序设计题
(1)
#include
main()
{
doublea,b,c,d;
doubleaver=0.0;
printf("\nPleaseinputfourdoublenumber:
");
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
aver=(a+b+c+d)/4;
printf("\nTheaverageofthefourdoublenumberis%lf",aver);
}
(2)
#include
#definePI3.14159
main()
{
doubler;
doublearea=0,len=0;
printf("\nPleaseinputr:
");
scanf("%lf",&r);
area=PI*r*r;
len=2*PI*r;
printf("\narea=%lf,length=%lf",area,len);
}
(3)
#include
main()
{
floati,s;
printf("\nPleaseinputdata:
");
scanf("%f%f",&i,&s);
s=s*(1+i);
printf("\nIhave%.2fyuanafteroneyear.",s);
}
第三章
1、选择题
(1)C
(2)C(3)A(4)C(5)D(6)A(7)C(8)A(9)B(10)D
2、填空题
(1)&m,&n
m=n;
n=temp;
m,n
(2)
554
554
334
(3)9
i+1
"%d",i
printf("\n");
(4)73
-543
93201
3、程序设计题
(1)
#include
#include
main()
{
doublea,b,c,d,det,a_2,real,imag,x1,x2;
printf("Pleaseentera,b,c:
");
scanf("%lf%lf%lf",&a,&b,&c);
if(a==0&&b==0)
printf("Noroot!
\n");
elseif(a==0)
printf("Lineequationrootis%.2lf\n",-c/b);
else
{
d=b*b-4*a*c;
det=sqrt(fabs(d));
a_2=2*a;
if(d<0)
{
real=-b/a_2;
imag=det/a_2;
printf("Thetworootare:
\n%.2lf+%.2lfi\n",real,imag);
printf("and\n%.2lf-%.2lfi\n",real,imag);
}
elseif(d==0)
printf("Singlerealrootis%.2lf:
\n",-b/a_2);
else
{
x1=-b/(a_2)+det/a_2;
x2=-b/(a_2)+det/a_2;
printf("Thetworealrootsare:
\n%.2lf\nand\n%.2lf\n",x1,x2);
}
}
}
(2)
#include
main()
{
inti,j;
for(i=1;i<=9;i++)
{
for(j=1;j<=9;j++)
printf("%d*%d=%2d",i,j,i*j);
printf("\n");
}
}
(3)#include
main()
{
floatsum,product;
inti,n,j;
printf("\nEntern\(4<=n<=20):
");
scanf("%d",&n);
while(n>20||n<4)
{
printf("\nEnternagain:
");
scanf("%d",&n);
}
sum=0;
product=1;
for(i=1;i<=n;i++)
{
product=1;
for(j=1;j<=i;j++)
product=product*j;
sum=sum+product;
}
printf("1!
+2!
+...+%d!
=%.0f\n",n,sum);
}
第四章
1、选择题
(1)C
(2)D(3)B(4)D(5)C(6)B(7)B(8)C(9)A(10)C(11)C(12)B
2、填空题
(1)
intmen[10];
floatstep[4]={1.9,-2.33,0,20.6};
_intgrid[4][10];
(2)
intm[10]={9,4,7,49,32,-5};
09
scanf("%d",m[1]);
m[0]=39;
m[0]=a[3]+a[5];
(3)
3
5
8
8
9
12
9
(4)
inta[10]={9,4,12,8,2,10,7,5,1,3};
09
88
(5)10
3、程序填空题
(1)
array[20]
20
&array[i]
20
max=array[i];
min=array[i];
sum+array[i];
sum/20
(2)
-5.770000
2
1
(3)
ABCDEFGHIJKL
EFGHIJKL
ABFDEFGHIJKL
ABFDEFGHI
4、程序设计题
(1)
#defineSIZE100
#include
voidmain()
{
inta[SIZE+1],i,j;
for(i=2;i<=100;i++)
a[i]=i;
for(i=2;i<=100;i++)
for(j=i+1;j<=100;j++)
if(a[i]!
=0&&a[j]%a[i]==0)
a[j]=0;
printf("\n");
j=0;
for(i=2;i<=100;i++)
{
if(a[i]!
=0)
{
printf("%-4d",a[i]);
j++;
}
if(j==10)
{
j=0;
printf("\n");
}
}
}
(2)
#defineS14
#include"stdio.h"
voidmain()
{
inta[S][S],i,j,n;
printf("pleaseentern:
");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a[i][i]=1;
a[i][1]=1;
}
for(i=3;i<=n;i++)
for(j=2;j
a[i][j]=a[i-1][j-1]+a[i-1][j];
for(i=1;i<=n;i++)
{
for(j=1;j<=n-i;j++)
printf("");
for(j=1;j<=i;j++)
printf("%3d",a[i][j]);
printf("\n");
}
}
(3)
#defineSIZE80
#include
voidmain()
{
charstr1[SIZE+SIZE],str2[SIZE];
inti,j;
puts("Pleaseenter2string:
");
scanf("%s",str1);
scanf("%s",str2);
i=0;
while(str1[i]!
='\0')
i++;
j=0;
while(str2[j]!
='\0')
{
str1[i]=str2[j];
i++;
j++;
}
str1[i]='\0';
printf("%s\n",str1);
}
(4)
#defineSIZE80
#include
#include
voidmain()
{
charstring[SIZE];
intlen,i,j,flag;
longnumber;
puts("Pleaseenteradigitalstring:
");
scanf("%s",string);
len=strlen(string);
if(string[0]=='-')
{
flag=-1;
i=1;
}
else
{
flag=1;
i=0;
}
number=string[i]-'0';
for(i++;i number=number*10+(string[i]-'0'); number=flag*number; printf("%d\n",number); } (5) #defineSIZE40 #include voidmain() { intm,n,i,j; floatprice[SIZE],sum; printf("\nPleaseinputMandN: "); scanf("%d%d",&m,&n); m=m-n; printf("Pleaseinput%dprice: ",n); sum=0; for(i=0;i { scanf("%f",&price[i]); sum=sum+price[i]; } printf("Averare%10.2f.",sum/n); while(m>0) { for(i=0;i price[i]=price[i+1]; printf("\nPleaseinputoneprice: "); scanf("%f",&price[n-1]); m--; sum=0; for(i=0;i { sum=sum+price[i]; } printf("Aberare%10.2f",sum/n); } } 第五章 1.选择题 (1)C (2)D(3)C(4)B(5)A(6)A(7)A(8)B(9)A(10)B(11)A(12)A 2.填空题 (1)整型 (2)值传递 地址传递 (3)全局变量 局部变量 (4)自动变量 静态变量 寄存器变量 外部变量 (5)自动变量 (6)15 300 (7)8 121 (8)x=3,y=4,n=7 (9)56 3.程序设计题 (1) #include intgcd_recursion(inta,intb); voidmain() { inti,j; puts("\nPleaseenter2integer"); scanf("%d,%d",&i,&j); if(i<0||j<0) { puts("\nDataError! Pleaseenter2integer"); scanf("%d,%d",&i,&j); } else printf("gcd(%d,%d)=%d",i,j,gcd_recursion(i,j)); } intgcd_recursion(inta,intb) {intc,d; if(a {c=a; a=b; b=c; if(a%b==0) returnb; else d=gcd_recursion(b,a%b); } elseif(a%b==0) returnb; else d=gcd_recursion(b,a%b); returnd; } (2) #include intdelete_char(charc,charstr[]); voidmain() {charstr[10],c,i; puts("\nPleaseenterastring: "); gets(str); puts("Pleaseenteracharyouwanttodelete: "); c=getchar(); puts("Beforedeleted: "); puts(str); puts("Afterdeleted: "); i=delete_char(c,str); puts(str); printf("Thereare%dcharactersdeleted.",i); } intdelete_char(charc,charstr[]) {inti,j,total,k,sum; i=0; total=0; while(str[i]! ='\0') { k=i; sum=0; while(str[k]==c) {k++; sum++; } total=total+sum; if(str[i]==c) {for(j=i;str[j+sum]! ='\0';j++) str[j]=str[j+sum]; str[j]='\0'; } i++; } returntotal; } (3) #include intmax(inta,intb); voidmain() { inti,j,k; puts("\nPleaseenter3integer: "); scanf("%d,%d,%d",&i,&j,&k); printf("maxis%d.",max(max(i,j),k)); } intmax(inta,intb) {if(a>b) returna; else returnb; } (4) #include voidint_string(longa,charstr[]); voidreverse(charc[],intsize); voidinsert_space(charc[],intsize); voidmain() { longi; charstr1[10]; puts("\nPleaseenter1longinterger: "); scanf("%d",&i); int_string(i,str1); printf("digitalstringis%s",str1); } voidint_string(longa,charstr[]) { inti=0; while(a! =0) { str[i]=a%10+'0'; a=a/10; i++; } str[i]='\0'; insert_space(str,i); } voidinsert_space(charc[],intsize) { inti; c[2*size-1]='\0'; for(i=2*(size-1);i>=2;i-=2) { c[i]=c[i/2]; c[i-1]=''; } } (5) #include longfacto(longx); main() { inta; longfactorial; printf("\nPleaseenterainteger: "); scanf("%d",&a); factorial=facto(a); printf("\nThe%d'sjiecengis: %ld\n",a,factorial); } longfacto(longx) { if(x==1) return1; else return(x*facto(x-1)); } (6) #include floataverage(floatmath,floatchinese,floatenglish); main() { floatscore[3]; floataver; printf("Pleaseenteryourscore: math,chinese,english\n"); scanf("%f,%f,%f",&score[0],&score[1],&score[2]); aver=average(score[0],score[1],score[2]); printf("Youraverageis%.2f\n",aver); } floataverage(floatmath,floatchinese,floatenglish) { return(math+chinese+english)/3; } (7) #include floatmax=0,min=0; floataverage(floatarr[],intn) { inti; floataver,sum=arr[0]; max=min=arr[0]; for(i=1;i { if(arr[i]>max) max=arr[i]; elseif(arr[i min=arr[i]; sum=sum+arr[i]; } aver=sum/n; return(aver); } main() { floatscore[10],aver; inti; printf("Pleaseentertenscore: "); for(i=0;i<10;i++) scanf("%f",&score[i]); aver=average(score,10); printf("max=%.2f\nmin=%.2f\naverage=%.2f\n",max, min,aver); } (8) #include intfib(intn) { if((n==1||n==2)) return1; else return(fib(n-1)+fib(n-2)); } voidmain() { inti; printf("\n"); for(i=1;i<20;i++) { printf("%-12d",fib(i)); if(i%5==0) printf("\n"); } } 第六章 1、选择题 (1)A (2)C(3)A(4)B(5)B(6)D(7)D(8)B(9)D(10)B 2、填空题 (1)a=10,b=20 a=20,b=10 (2)**pp=60 3、程序设计题 (1) #include char*month_name(intn); voidmain() { intn; printf("\nPleaseenter1integer: "); scanf("%d",&n); printf("%dmonth: %s\n",n,month_name(n)); } char*month_name(intn) { staticchar*name[]={"illegalmonth", "Jan","Feb","Mar","Apr","May","Jun", "July","Aug","Sept","Oct","Nov","Dec"}; return((n<1||n>12)? name[0]: name[n]); } (2) #include #defineN10 sort(intdata[]) { inti,j,min_a,temp; for(i=0;i { min_a=i; for(j=i+1;j if(*(data+j)<*(data+min_a)) min_a=j; if(min_a! =i) { temp=*(data+min_a); *(data+min_a)=*(data+i); *(data+i)=temp; } } } main() { inti,j,data[N],temp; intmin_a; printf("\nPleaseinput%dint: \n",N); for(i=0;i scanf("%d",&data[i]); sort(data); printf("Aftersorted: \n"); for(i=0;i printf("%d",data[i]); } (3) #include voidreverse(char*c);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C语言程序设计课后习题答案 吉林大学版 武爱平 语言程序设计 课后 习题 答案 吉林大学
![提示](https://static.bdocx.com/images/bang_tan.gif)