C语言程序设计课后习题答案吉林大学版武爱平.docx
《C语言程序设计课后习题答案吉林大学版武爱平.docx》由会员分享,可在线阅读,更多相关《C语言程序设计课后习题答案吉林大学版武爱平.docx(38页珍藏版)》请在冰豆网上搜索。
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)35889129
(4)inta[10]={9,4,12,8,2,10,7,5,1,3};0988
(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++;inumber=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);