C语言程序设计课后习题答案吉林大学版武爱平文档格式.docx
《C语言程序设计课后习题答案吉林大学版武爱平文档格式.docx》由会员分享,可在线阅读,更多相关《C语言程序设计课后习题答案吉林大学版武爱平文档格式.docx(39页珍藏版)》请在冰豆网上搜索。
(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.程序设计题
doublea,b,c,d;
doubleaver=0.0;
printf("
\nPleaseinputfourdoublenumber:
scanf("
%lf%lf%lf%lf"
&
c,&
d);
aver=(a+b+c+d)/4;
\nTheaverageofthefourdoublenumberis%lf"
aver);
}
#include<
#definePI3.14159
doubler;
doublearea=0,len=0;
\nPleaseinputr:
%lf"
r);
area=PI*r*r;
len=2*PI*r;
\narea=%lf,length=%lf"
area,len);
(3)
floati,s;
\nPleaseinputdata:
%f%f"
i,&
s);
s=s*(1+i);
\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
(4)73
-543
93201
3、程序设计题
(1)
math.h>
doublea,b,c,d,det,a_2,real,imag,x1,x2;
Pleaseentera,b,c:
scanf("
%lf%lf%lf"
c);
if(a==0&
&
b==0)
Noroot!
elseif(a==0)
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;
Thetworootare:
\n%.2lf+%.2lfi\n"
real,imag);
and\n%.2lf-%.2lfi\n"
}
elseif(d==0)
Singlerealrootis%.2lf:
-b/a_2);
else
x1=-b/(a_2)+det/a_2;
x2=-b/(a_2)+det/a_2;
Thetworealrootsare:
\n%.2lf\nand\n%.2lf\n"
x1,x2);
inti,j;
for(i=1;
i<
=9;
i++)
for(j=1;
j<
j++)
%d*%d=%2d"
i,j,i*j);
(3)#include<
floatsum,product;
inti,n,j;
\nEntern\(4<
=n<
=20):
n);
while(n>
20||n<
4)
\nEnternagain:
sum=0;
product=1;
=n;
{
=i;
product=product*j;
sum=sum+product;
1!
+2!
+...+%d!
=%.0f\n"
n,sum);
第四章
(1)C
(2)D(3)B(4)D(5)C(6)B(7)B(8)C(9)A(10)C(11)C(12)B
(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
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、程序填空题
array[20]
20
&
array[i]
max=array[i];
min=array[i];
sum+array[i];
sum/20
-5.770000
2
1
ABCDEFGHIJKL
EFGHIJKL
ABFDEFGHIJKL
ABFDEFGHI
4、程序设计题
#defineSIZE100
voidmain()
inta[SIZE+1],i,j;
for(i=2;
=100;
a[i]=i;
for(j=i+1;
if(a[i]!
=0&
a[j]%a[i]==0)
a[j]=0;
j=0;
=0)
%-4d"
a[i]);
j++;
if(j==10)
#defineS14
#include"
stdio.h"
inta[S][S],i,j,n;
pleaseentern:
a[i][i]=1;
a[i][1]=1;
for(i=3;
for(j=2;
i;
a[i][j]=a[i-1][j-1]+a[i-1][j];
=n-i;
"
%3d"
a[i][j]);
#defineSIZE80
charstr1[SIZE+SIZE],str2[SIZE];
puts("
Pleaseenter2string:
%s"
str1);
str2);
i=0;
while(str1[i]!
='
\0'
)
i++;
while(str2[j]!
str1[i]=str2[j];
str1[i]='
;
%s\n"
(4)
string.h>
charstring[SIZE];
intlen,i,j,flag;
longnumber;
Pleaseenteradigitalstring:
string);
len=strlen(string);
if(string[0]=='
-'
flag=-1;
i=1;
flag=1;
number=string[i]-'
0'
for(i++;
len;
number=number*10+(string[i]-'
number=flag*number;
%d\n"
number);
(5)
#defineSIZE40
intm,n,i,j;
floatprice[SIZE],sum;
\nPleaseinputMandN:
%d%d"
m=m-n;
Pleaseinput%dprice:
n);
for(i=0;
n;
%f"
price[i]);
sum=sum+price[i];
}
Averare%10.2f."
sum/n);