《C语言程序设计》苏小红课后习题答案高等教育出版社Word文档格式.docx
《《C语言程序设计》苏小红课后习题答案高等教育出版社Word文档格式.docx》由会员分享,可在线阅读,更多相关《《C语言程序设计》苏小红课后习题答案高等教育出版社Word文档格式.docx(49页珍藏版)》请在冰豆网上搜索。
![《C语言程序设计》苏小红课后习题答案高等教育出版社Word文档格式.docx](https://file1.bdocx.com/fileroot1/2022-11/27/3a4cefa9-4a6c-4086-b809-7e85d9dea891/3a4cefa9-4a6c-4086-b809-7e85d9dea8911.gif)
floatn,capital,deposit;
Inputn,capital:
%f,%f"
n,&
capital);
deposit=capital*pow(1+rate,n);
deposit=%f\n"
deposit);
3.4
floata,b,c;
doublex,y;
Inputa,b,c:
%f%f%f"
&
a,&
b,&
c);
x=(-b+sqrt(b*b-4*a*c))/(2*a);
y=(-b-sqrt(b*b-4*a*c))/(2*a);
x=%f,y=%f\n"
习题4
4.1
(1)
charc1='
a'
c2='
b'
c3='
c'
;
a%cb%cc%c\n"
c1,c2,c3);
4.1
(2)
inta=12,b=15;
a=%d%%,b=%d%%\n"
a,b);
4.1(3)
inta,b;
%2d%*2s%2d"
a,&
b);
%d,%d\n"
4.2
longa,b;
floatx,y;
%f,%f\n"
x,&
y);
a=%d,b=%d\n"
x=%f,b=%f\n"
5.1
floata;
Inputa:
%f"
a);
if(a>
=0)
a=a;
a=%f\n"
a);
else
a=-a;
5.2
inta;
if(a%2==0)
a是偶数"
a是奇数"
5.3
floata,b,c,s,area;
if(a+b>
c&
&
a+c>
b&
b+c>
a)
s=(a+b+c)/2;
area=(float)sqrt(s*(s-a)*(s-b)*(s-c));
area=%f\n"
area);
不是三角形"
5.4
floata,b,c,x,y;
Inputa,b,c:
%f,%f,%f"
b,&
if(a==0)
该方程不是一元二次方程\n"
if(b*b-4*a*c>
0)
elseif(b*b-4*a*c==0)
x=-b/(2*a);
y=-b/(2*a);
该方程无实根\n"
5.5
intyear,flag;
Inputayear:
year);
if(year%4==0&
year%400!
=0||year%400==0)
flag=1;
flag=0;
if(flag==1)
%disaleapyear!
\n"
year);
%disnotaleapyear!
5.6
flag=year%400==0||year%4==0&
year%100!
=0?
1:
0;
if(flag==1&
flag!
5.7
charch;
Inputch:
%c"
ch);
if(ch>
='
ch<
z'
)
ch=getchar();
ch=ch-32;
%c,%d\n"
ch,ch);
elseif(ch>
A'
Z'
ch=ch+32;
ch);
5.8
=48&
=57)
ch是数字字符\n"
=65&
=90)
ch是大写字母\n"
=97&
=122)
ch是小写字母\n"
elseif(ch==32)
ch是空格\n"
ch是其他字符\n"
5.9
intscore,grade;
Inputscore:
score);
grade=score/10;
if(score<
0||score>
100)
Inputerror\n"
if(score>
=90&
score<
=100)
%d--A\n"
score);
elseif(score>
=80&
90)
%d--B\n"
=70&
80)
%d--C\n"
=60&
70)
%d--D\n"
=0&
60)
%d--E\n"
5.10
intyear,month;
Inputyear,month:
%d,%d"
year,&
month);
if(month>
12||month<
errormonth\n"
switch(year,month)
case12:
case10:
case8:
case7:
case5:
case3:
case1:
31天\n"
break;
case11:
case9:
case6:
case4:
30天\n"
case2:
year!
29天\n"
28天\n"
default:
6.1
(1)
inti,j,k;
charspace='
'
for(i=1;
i<
=4;
i++)
for(j=1;
j<
=i;
j++)
space);
for(k=1;
k<
=6;
k++)
*"
6.1
(2)#include<
intk=4,n;
for(n=0;
n<
k;
n++)
if(n%2==0)continue;
k--;
k=%d\n,n=%d\n"
k,n);
6.1(3)#include<
if(n%2==0)break;
k=%d,n=%d\n"
6.2
(1)#include<
inti,sum=0;
=101;
sum=sum+i;
sum=%d\n"
sum);
6.2
(2)#include<
longi;
longterm,sum=0;
i=i+2)
term=i*(i+1)*(i+2);
sum=sum+term;
sum=%ld\n"
6.2(4)#include<
intn=1;
floatterm=1.0,sign=1,sum=0;
while(term<
=-1e-4||term>
=1e-4)
term=1.0/sign;
sign=sign+n;
n++;
sum=%f\n"
6.2(5)#include<
intn=1,count=1;
floatx;
doublesum,term;
Inputx:
sum=x;
term=x;
do{
term=-term*x*x/((n+1)*(n+2));
n=n+2;
count++;
}while(fabs(term)>
=1e-5);
sin(x)=%f,count=%d\n"
sum,count);
6.3#include<
intx=1,find=0;
while(!
find)
if(x%2==1&
x%3==2&
x%5==4&
x%6==5&
x%7==0)
x=%d\n"
find=1;
x++;
/*intx,find=0;
for(x=1;
!
find;
x++)
}*/
6.4#include<
inti,n;
longp=1,m=1;
Inputn:
n);
=n;
p=i*i;
m=i*i*i;
p=%d,m=%d\n"
i,p,i,m);
6.5#include<
floatc,f;
for(c=-40;
c<
=110;
c=c+10)
f=9/5*c+32;
f=%f\n"
f);
6.6#include<
intn;
doublec=0.01875,x;
x=x*pow(1+c,12)-1000;
}while(x>
0);
6.7#include<
intn=0;
floata=100.0,c;
Inputc:
do
a=a*(1+c);
}while(a<
=200);
n=%d\n"
n);
6.8#include<
doublesum=1,term=1;
while(fabs(term)>
=1e-5)
term=pow(-1,count)*(1.0/(n+2));
sum=4*sum;
printf("
sum=%f,count=%d\n"
6.9#include<
term=term*(1.0/n);
6.10#include<
intx;
for(x=100;
x<
=999;
if(x==pow(x/100,3)+pow(x/10%10,3)+pow(x%10,3))
6.11#include<
inti=0,n;
longsum=0,term=1;
Inputn:
i++;
term=term*i;
}while(sum<
i-1);
6.12#include<
inti,n,m,count=0,sum=0;
Inputm:
m);
if(m>
sum=sum+m;
sum=%d,count=%d\n"
6.13#include<
0||m<
6.14#include<
intx,y,z;
for(x=0;
=17;
for(y=0;
y<
=25;
y++)
3*x+2*y+z==50;
z=30-x-y;
if(3*x+2*y+z==50&
x+y+z==30)
x=%d,y=%d,z=%d\n"
x,y,z);
6.15#include<
intx,y;
=98;
y=98-x;
2*x+4*y==386;
if(x+y==98&
2*x+4*y==386)
x=%d,y=%d\n"
6.16#include<
=20;
=33;
3*y+5*x+z/3.0==100;
z=100-x-y;
if(5*x+3*y+z/3.0==100&
z+x+y==100)
6.17#include<
for(x=1;
=9;
for(y=1;
10*x+5*y+z==100;
z=50-x-y;
if(10*x+5*y+z==100&
x+y+z==50&
z>
7.1#include<
intSquare(inti)
returni*i;
intmain()
inti=0;
i=Square(i);
for(;
3;
staticinti=1;
i+=Square(i);
%d,"
i);
return0;
7.2#include<
inthour,minute,second;
voidupdate()
second++;
if(second==60)
second=0;
minute++;
if(minute==60)
minute=0;
hour++;
if(hour==24)
hour=0;
voiddisplay()
%d,%d,%d\n"
hour,minute,second);
voiddelay()
intt;
for(t=0;
t<
100000000;
t++);
inti;
voidupdaye(),display(),delay();
for(i=0;
1000000;
update();
display();
delay();
7.3#include<
intGetMax(inta,intb);
intx,y,max;
Inputx,y:
max=GetMax(x,y);
max=%d\n"
max);
intGetMax(intm,intn)
=n)
returnm;
returnn;
7.4#include<
intLCM(intn,intm);
Inputa,b:
%d\