C语言程序习题答案Word下载.docx
《C语言程序习题答案Word下载.docx》由会员分享,可在线阅读,更多相关《C语言程序习题答案Word下载.docx(20页珍藏版)》请在冰豆网上搜索。
f=64.0;
c=(5.0/9)*(f-32);
f%f\nc%f\n"
f,c);
}
例3.2:
{floatp0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3;
p1=p0*(1+r1);
p2=p0*(1+r2);
p3=p0*(1+r3/2)*(1+r3/2);
p1=%f\np2=%f\np3=%f\n"
p1,p2,p3);
return0;
例3.3:
{charc1,c2;
c1='
A'
;
c2=c1+32;
%c\n"
c2);
%d\n"
例3.4:
math.h"
{doublea,b,c,s,area;
a=3.67;
b=5.43;
c=6.21;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
a=%f\tb=%f\tc=%f\n"
a,b,c);
area=%f\n"
area);
例3.5:
#include"
{doublea,b,c,disc,x1,x2,p,q;
%lf%lf%lf"
b,&
c);
disc=b*b-4*a*c;
p=-b/(2.0*a);
q=sqrt(disc)/(2.0*a);
x1=p+q;
x2=p-q;
x1=%7.2f\nx2=%7.2f\n"
x1,x2);
例3.6:
{doublea=1.0;
%10.15f\n"
a/3);
例3.7:
{floata;
a=10000/3.0;
%f\n"
a);
例3.8:
{chara='
B'
b='
O'
c='
Y'
putchar(a);
putchar(b);
putchar(c);
putchar("
\n"
return;
例3.9:
{chara,b,c;
a=getchar();
b=getchar();
c=getchar();
putchar(a);
putchar(b);
putchar(c);
putchar("
return0;
例3.10:
c1=getchar();
c2=c1+32;
putchar(c2);
例4.1:
if(disc<
0)
Thisequationhasnitrealroots\n"
else
{p=-b/(2.0*a);
q=sqrt(disc)/(2.0*a);
x1=p+q;
x2=p-q;
printf("
realroots:
\nx1=%7.2f\nx2=%7.2f\n"
return0;
例4.2:
{floata,b,t;
%f,%f"
if(a>
b)
{t=a;
a=b;
b=t;
%5.2f,%5.2f\n"
a,b);
例4.3:
{floata,b,c,t;
%f,%f,%f"
a=b;
b=t;
c)
a=c;
c=t;
if(b>
{t=b;
b=c;
%5.2f,%5.2f,%5.2f\n"
例4.4:
{charch;
%c"
ch);
ch=(ch>
='
&
ch<
Z'
)?
(ch+32):
ch;
ch);
例4.5:
{intx,y;
%d"
x);
if(x>
=0);
y=1;
y=0;
y=-1;
x=%d,y=%d"
x,y);
习题4.8:
{intgrade;
grade);
if(grade>
=90)
A"
=80)
B"
=70)
C"
=60)
D"
E"
例4.9:
{inti,n;
i);
n=i/10000;
i=1%10000;
n=%d\n"
n);
n=i/1000;
i=1%1000;
n=i/100;
i=1%100;
n=i/10;
i=1%10;
n=i;
{longn,i;
i=i%10000;
i=i%1000;
i=i%100;
i=i%10;
{longn,a,b,c,d,e;
Pleaseinputanumber\n"
n);
if(n/10000>
=1)
{a=n/10000;
n=n%10000;
b=n/1000;
n=n%1000;
c=n/100;
n=n%100;
d=n/10;
e=n%10;
Thisisa5'
weishu'
%d\n%d\n%d\n%d\n%d\n"
a,b,c,d,e);
{if(n/1000>
{b=n/1000;
n=n%1000;
n=n%100;
d=n/10;
printf("
Thisisa4'
%d\n%d\n%d\n%d\n"
b,c,d,e);
else
{if(n/100>
{c=n/100;
Thisisa3'
%d\n%d\n%d\n"
c,d,e);
{if(n/10>
{d=n/10;
Thisisa2'
%d\n%d\n"
d,e);
{printf("
Thisisa1'
}
例5.1:
{inti=1,sum=0;
do
{sum=sum+i;
i=i+1;
while(i<
=100);
sum=%d\n"
例5.2:
例5.3:
{inti,sum=0;
pleaseenteri,i=?
"
=10)
i++;
例5.4:
{intn;
for(n=100;
n<
=200;
n++)
{if(n%3==0)
continue;
例5.5:
{inti,j,n=0;
for(i=1;
i<
=4;
i++)
for(j=1;
j<
=5;
j++,i++)
{if(n%5==0)
%d\t"
i*j);
printf('
例5.6:
{for(j=1;
j++,n++)
%d"
例5.7:
{intf1=1,f2=1,f3,i;
f1,f2);
=38;
{f3=f1+f2;
f3);
fi=f2;
f2=f3;
例5.8:
f1=f2;
}
例5.9:
{intn,i;
pleaseenteranintegernumber,n=?
for(i=2;
=n-1;
{if(n%i==0)
{printf("
numberisasushu"
break;
else
{continue;
}}
numberisnotasushu"
例5.10:
{inti,n,k=0;
for(n=101;
n=n+1)
{{for(i=2;
{if(n%i==0)
k=k+1;
if(k>
break;
习题5.5:
{inta,b,n,k;
doublec=0,t=1;
%d%d"
b=a;
for(k=1;
k<
=n;
k++)
{c=a+c;
t=10*t;
a=a+b*t;
%f"
习题5.6:
{floatn=1,k=1,s=0;
while(n<
=4)
{s=s+k;
n=n+1;
k=k*n;
s);
习题5.7:
{floatk=1,s=0;
while(k<
=100)
k=k+1;
k=1;
=50)
{s=s+k*k;
{s=s+1/k;
s=%f"
习题5.8:
{intn,i,j,k;
=999;
{i=n/100;
j=n%100;
j=j/10;
k=n%10;
if(n==i*i*i+j*j*j+k*k*k)
习题5.10:
{floati=1,j=2,k=3,s=2,n,a;
for(n=2;
=20;
{s=s+k/j;
i=j;
a=k;
k=j+k;
j=a;
习题5.16:
{inti,j,k;
for(i=0;
=3;
{for(j=0;
=2-i;
j++)
"
for(k=0;
=2*i;
*"
=2;
=i;
j++)
=4-2*i;
例6.1:
{inti,a[10];
=9;
a[i]=i;
for(i=9;
i>
=0;
i--)
%d"
a[i]);
例6.2:
{inti;
intf[20]={1,1};
20;
f[i]=f[i-1]+f[i-2];
{if(i%5==0)
%12d"
f[i]);
例6.3:
{inta[10];
inti,j,t;
input10number:
10;
a[i]);
for(j=0;
9;
9-j;
if(a[i]>
a[i+1])
{t=a[i];
a[i]=a[i+1];
a[i+1]=t;
thesortednumbers:
例7.1:
{voidprint_star();
voidprint_message();
print_star();
print_message();
voidprint_star()
**********\n"
voidprint_message()
{printf