C语言程序设计导学第三版参考答案 杜友福 编Word文档格式.docx
- 文档编号:474132
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:25
- 大小:18.70KB
C语言程序设计导学第三版参考答案 杜友福 编Word文档格式.docx
《C语言程序设计导学第三版参考答案 杜友福 编Word文档格式.docx》由会员分享,可在线阅读,更多相关《C语言程序设计导学第三版参考答案 杜友福 编Word文档格式.docx(25页珍藏版)》请在冰点文库上搜索。
%frmb=%f$\n"
rmb,dollar);
实验二
2.程序填空题
num%10、num/100%10、g+b==s
flag=0、year%100!
=0、year%400==0
3.程序改错题
switch(grade)
case10:
case6:
grade=D\n"
break;
4.程序设计题
include<
intx,n;
scanf("
x);
if(x<
0)x=-x;
if(x>
=100000)x=x%100000;
if(x>
=10000)n=5;
elseif(x>
=1000)n=4;
=100)n=3;
=10)n=2;
elsen=1;
printf("
%dhas%ddigits\n"
x,n);
switch(n)
{
case1:
%d\n"
x);
break;
case2:
%d%d\n"
x%10,x/10);
case3:
%d%d%d\n"
x%10,x/10%10,x/100);
case4:
%d%d%d%d\n"
x%10,x/10%10,x/100%10,x/1000);
case5:
%d%d%d%d%d\n"
x%10,x/10%10,x/100%10,x/1000%10,x/10000);
}
floata,b,c,max;
if(a>
b)
max=a;
else
max=b;
max=max>
c?
max:
c;
max=%g\n"
max);
实验三
&
m、i<
=m、t+1.0/(i*i)
m<
n、i<
=m、t*k
%ld"
m);
if(d%2!
=0)
m=m/t;
voidmain()
intx,s=0;
for(x=50;
x<
=180;
x++)
if(x%3==0&
&
x%4==0)
%d"
s=s+x;
\nsum=%d\n"
s);
inta,b,c,d,e;
for(a=1;
a<
=9;
a++)
for(b=0;
b<
b++)
for(c=0;
c<
c++)
for(d=0;
d<
d++)
for(e=2;
e<
e++)
if((a*1000+b*100+c*10+d)*e==d*1000+c*100+b*10+a)
%d%d%d%d*%d=%d%d%d%d\n"
a,b,c,d,e,d,c,b,a);
实验四
m=m-n、n=n-m、m!
=n
a==0||diac<
0、(-b+sqrt(disc))/(2*a)、
(-b-sqrt(disc))/(2*a)
t=1.0/((2*n-1)*(2*n+1));
while(t>
=0.00001);
intx,a,b,c;
for(x=200;
=300;
a=x/100;
b=x/10%10;
c=x%10;
if(a+b+c==12&
a*b*c==42)
\n"
math.h>
floata,c,fa,f1a,fc;
a=88;
do
fa=5*a*a*a*a*a-8*a*a*a+10*a*a-7*a+25;
f1a=25*a*a*a*a-24*a*a+20*a-7;
c=a-fa/f1a;
fc=5*c*c*c*c*c-8*c*c*c+10*c*c-7*c+25;
a=c;
}while(fabs(fc)>
0.0001);
x=%f,y=%f\n"
c,fc);
实验五
a[i][j]、a[0][0]、i、j、max
x=a[i]、a[j]=x
inta[N]={1,5,8,7,6,3,2,4};
for(i=0;
i<
N-1;
i++)
t=a[i],a[i]=a[k],a[k]=t;
inti,j,f=0,a[3][4]={1,2,3,4,5,6,7,-8,9,10,-11,12};
(i<
3&
f==0);
for(j=0;
j<
4;
j++)
if(a[i][j]<
0)
{
f=1;
i=%d,j=%d\n"
i,j);
break;
}
if(f==0)
nofound!
#defineN10
inti,j,s;
//inta[N]={1,3,5,7,9,11,13,15,17};
inta[N]={17,15,13,11,9,7,5,3,1};
s);
i=0;
if(a[0]<
a[1])
while(s>
a[i])i++;
while(s<
for(j=N-1;
j>
i;
j--)
a[j]=a[j-1];
a[j]=s;
N;
%3d"
a[i]);
实验六
str[i]!
='
\0'
、bb[5]++、bb[i]或bb[5]
for(k=0;
substr[k]==str[i+k];
k++)
if(substr[k+1]=='
)
string.h>
charstr[81],c;
inti,j;
Inputastring:
gets(str);
Inputachar:
c=getchar();
str[i]!
;
if(str[i]==c)
for(j=i;
strlen(str);
str[j]=str[j+1];
i--;
puts(str);
charstr[81],substr[81];
inti,n=-1;
Inputasubstring:
gets(substr);
for(k=0;
k++)if(substr[k+1]=='
{n=i;
}
n=%d\n"
n);
实验七
n-1、a[j+1]、a[j+1]、s
intleap(intyear)
flag=flag||(year%400==0);
if(leap(y)==1)
intisprime(int);
if(isprime(x))
{s=s+x;
\nsumofprime=%d\n"
intisprime(intn)
inti,flag=1;
for(i=2;
n;
if(n%i==0)
{flag=0;
}
return(flag);
#defineN10
voidsort(inta[],intn)
{
inti,j,k,t;
n-1;
k=i;
for(j=i+1;
if(a[j]<
a[k])
k=j;
t=a[k];
a[k]=a[i];
a[i]=t;
inti,x[10]={5,7,4,2,8,6,1,9,0,3};
theoriginalarray:
x[i]);
sort(x,N);
thesortedarray:
实验八
f(a)*f(b)、x=newx(x,b)、x=newx(a,x)
if(s[i]>
0'
s[i]<
9'
s[j++]=s[i];
s[j]='
voidfun(chars[],inti,intj)
chart;
if(i>
=j)
return;
t=s[i];
s[i]=s[j];
s[j]=t;
fun(s,i+1,j-1);
charstr[81];
fun(str,0,strlen(str)-1);
//sy8proc2.c
externdoublenewx(doublea,doubleb);
doublef(doublex)
doubley;
y=2*x*x*x-3*x*x+7*x-13;
return(y);
doublea,b,x;
do
Pleaseinputa,b:
%lf,%lf"
b);
}while(f(a)*f(b)>
0);
x=newx(a,b);
if(f(a)*f(x)>
x=newx(x,b);
x=newx(a,x);
}while(fabs(f(x))>
0.00001);
x=%lf,y=%lf\n"
x,f(x));
//sy8newx2.c
doublenewx(doublea,doubleb)
//或externdoublenewx(doublea,doubleb)
doublexnew;
xnew=(a*f(b)-b*f(a))/(f(b)-f(a));
return(xnew);
实验九
p=a、*(*p+j)
注:
外循环改为:
for(i=0;
3;
i++,p++)
pstr=s、*pstr-'
、pstr++
*ave=sum/n;
score+k);
/
Theresultis:
average(score,m,&
aver));
voidfun(char*pp)
inti,n=0;
while(*(pp+n)=='
*'
n++;
for(i=n;
*(pp+i)!
if(*(pp+i)!
*(pp+n)=*(pp+i);
*(pp+n)='
voidmain()
charaa[80];
Pleaseenterastring:
%s"
aa);
fun(aa);
Afterchanging,thestringbecome:
%s\n"
}
inti,k,n=0;
for(i=0;
if(*(pp+i)!
{
n++;
k=0;
else
k++;
if(k!
=0)
{
for(i=1;
=k;
*(pp+n+i)='
*(pp+n+i)='
*(pp+n)='
inti,k,j=0,n=0;
n++;
for(i=n;
*(pp+j)=*(pp+i);
j++;
else
k++;
if(k!
j-k;
*(pp+i)=*(pp+i);
*(pp+i)='
//或去掉此for循环,直接用*(pp+j-k)='
*(pp+j)='
(3)
while(*(pp+n)=='
实验十
(*p)、structstu、&
student[2]
}STREC;
if(a[i].sc<
a[j].sc)
fun(s,N);
typedefstruct
charnum[10];
intsc;
floatfun(STRECa[],intn)
inti,s=0;
floatave;
s=s+a[i].sc;
ave=(float)s/n;
returnave;
inti;
floataver;
STRECs[N]={{"
Li001"
85},{"
Li003"
76},{"
Li002"
69},
{"
Li004"
96},{"
Li006"
79},{"
Li005"
86},
Li008"
68},{"
Li007"
77},{"
Li010"
96},
Li009"
64}};
aver=fun(s,N);
i++)
if(s[i].sc>
aver)
%s:
s[i].num,s[i].sc);
intfun(STRECa[],intn)
inti,max=-1;
if(a[i].sc>
max)
max=a[i].sc;
returnmax;
inti,maxsc;
maxsc=fun(s,N);
if(s[i].sc==maxsc)
#defineM5//人数
#defineN3//课程数
structstudent
charnum[10];
charname[20];
floatscore[N+1];
};
structstudentstud[M];
inti,j,max;
floataver;
Inputdata:
\n"
NoNamescore1score2score3\n"
M;
%s%s"
stud[i].num,stud[i].name);
stud[i].score[0],&
stud[i].score[1],
stud[i].score[2]);
scoreaverage:
aver=0;
aver=aver+stud[i].score[j];
aver=aver/M;
%6.1f"
}
m
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- C语言程序设计导学第三版参考答案 杜友福 语言程序设计 第三 参考答案